|
|
|
@ -1,10 +1,12 @@
@@ -1,10 +1,12 @@
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
from flask import render_template, flash, redirect, url_for, abort |
|
|
|
|
from flask_login import current_user, login_required |
|
|
|
|
|
|
|
|
|
from app import db |
|
|
|
|
from app.main import bp |
|
|
|
|
from app.utils import generate_qr_code, serve_pil_image, get_game_if_owner |
|
|
|
|
from app.models import Objective, Role |
|
|
|
|
from app.models import Objective, Role, ObjectiveEncoder |
|
|
|
|
from app.main.forms import ObjectiveForm |
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/add_objective', methods=['GET', 'POST']) |
|
|
|
@ -14,14 +16,16 @@ def add_objective(game_name):
@@ -14,14 +16,16 @@ def add_objective(game_name):
|
|
|
|
|
form = ObjectiveForm() |
|
|
|
|
_objective = Objective(name='', latitude=52.0932, longitude=5.12405) |
|
|
|
|
if form.validate_on_submit(): |
|
|
|
|
_objective = Objective(name=form.objective_name.data, longitude=form.longitude.data, latitude=form.latitude.data) |
|
|
|
|
_objective = Objective(name=form.objective_name.data, longitude=form.longitude.data, |
|
|
|
|
latitude=form.latitude.data) |
|
|
|
|
_objective.set_hash() |
|
|
|
|
game.objectives.append(_objective) |
|
|
|
|
db.session.commit() |
|
|
|
|
flash("Objective has been added!") |
|
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
|
return render_template('objective.html', title=f'Add Objective for {game_name}', |
|
|
|
|
form=form, objective=_objective, owner=True) |
|
|
|
|
form=form, game=game, objective=_objective, owner=True, json=json, |
|
|
|
|
objective_encoder=ObjectiveEncoder) |
|
|
|
|
|
|
|
|
|
@bp.route('/objective/<objective_hash>/delete', methods=['GET']) |
|
|
|
|
@login_required |
|
|
|
@ -40,7 +44,8 @@ def objective_qrcode(objective_hash):
@@ -40,7 +44,8 @@ def objective_qrcode(objective_hash):
|
|
|
|
|
_objective = Objective.query.filter_by(hash=objective_hash).first_or_404() |
|
|
|
|
if not _objective.owned_by(current_user): |
|
|
|
|
abort(403) |
|
|
|
|
img = generate_qr_code(url_for('main.objective', objective_hash=_objective.hash, _external=True)) |
|
|
|
|
img = generate_qr_code(url_for('main.objective', objective_hash=_objective.hash, |
|
|
|
|
_external=True)) |
|
|
|
|
return serve_pil_image(img) |
|
|
|
|
|
|
|
|
|
@bp.route('/objective/<objective_hash>', methods=['GET', 'POST']) |
|
|
|
@ -49,7 +54,8 @@ def objective(objective_hash):
@@ -49,7 +54,8 @@ def objective(objective_hash):
|
|
|
|
|
_objective = Objective.query.filter_by(hash=objective_hash).first_or_404() |
|
|
|
|
if current_user.role_in_game(_objective.game) == Role.bunny: |
|
|
|
|
if not _objective.game.is_active(): |
|
|
|
|
flash("Its not find an objective before or after a game, or if the game is not in 'active' mode.") |
|
|
|
|
flash("It's not possible to find an objective before or after a game, " |
|
|
|
|
"or if the game is not in 'active' mode.") |
|
|
|
|
return redirect(url_for('main.game_dashboard', game_name=_objective.game.name)) |
|
|
|
|
player = current_user.player_in(_objective.game) |
|
|
|
|
if not _objective in player.found_objectives: |
|
|
|
@ -78,4 +84,5 @@ def objective(objective_hash):
@@ -78,4 +84,5 @@ def objective(objective_hash):
|
|
|
|
|
db.session.commit() |
|
|
|
|
return redirect(url_for('main.game_dashboard', game_name=_objective.game.name)) |
|
|
|
|
return render_template('objective.html', title='Objective view', |
|
|
|
|
objective=_objective, owner=True, form=form, qrcode=qrcode) |
|
|
|
|
form=form, game=_objective.game, objective=_objective, owner=True, |
|
|
|
|
qrcode=qrcode, json=json, objective_encoder=ObjectiveEncoder) |
|
|
|
|