|
|
@ -13,7 +13,7 @@ from sqlalchemy import and_ |
|
|
|
from app import db |
|
|
|
from app import db |
|
|
|
from app.main import bp |
|
|
|
from app.main import bp |
|
|
|
from app.utils import generate_qr_code, serve_pil_image |
|
|
|
from app.utils import generate_qr_code, serve_pil_image |
|
|
|
from app.models import User, Game, Role, GamePlayer, Objective, ObjectiveMinimalEncoder, LocationEncoder, PlayerCaughtPlayer |
|
|
|
from app.models import User, Game, Role, GamePlayer, Objective, ObjectiveMinimalEncoder, LocationEncoder, PlayerCaughtPlayer, Review |
|
|
|
from app.main.forms import CreateGameForm, ObjectiveForm, PlayerAddForm, UserCreateForm, PlayerUpdateForm, CatchBunnyForm |
|
|
|
from app.main.forms import CreateGameForm, ObjectiveForm, PlayerAddForm, UserCreateForm, PlayerUpdateForm, CatchBunnyForm |
|
|
|
|
|
|
|
|
|
|
|
@bp.before_app_request |
|
|
|
@bp.before_app_request |
|
|
@ -35,7 +35,8 @@ def index(): |
|
|
|
def create_game(): |
|
|
|
def create_game(): |
|
|
|
form = CreateGameForm() |
|
|
|
form = CreateGameForm() |
|
|
|
if form.validate_on_submit(): |
|
|
|
if form.validate_on_submit(): |
|
|
|
game = Game(name=form.game_name.data, start_time=form.start_time.data, end_time=form.end_time.data) |
|
|
|
game = Game(name=form.game_name.data, start_time=form.start_time.data, |
|
|
|
|
|
|
|
end_time=form.end_time.data) |
|
|
|
game.players.append(GamePlayer(user=current_user, role=Role['owner'])) |
|
|
|
game.players.append(GamePlayer(user=current_user, role=Role['owner'])) |
|
|
|
db.session.add(game) |
|
|
|
db.session.add(game) |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
@ -63,17 +64,18 @@ def game_dashboard(game_name): |
|
|
|
game = Game.query.filter_by(name=game_name).first_or_404() |
|
|
|
game = Game.query.filter_by(name=game_name).first_or_404() |
|
|
|
role = current_user.role_in_game(game) |
|
|
|
role = current_user.role_in_game(game) |
|
|
|
if role == Role.owner: |
|
|
|
if role == Role.owner: |
|
|
|
return render_template('game_owner_dashboard.html', title='Game Dashboard', |
|
|
|
return render_template('game_owner_dashboard.html', title='Game Dashboard', game=game, |
|
|
|
game=game, json=json, objective_encoder=ObjectiveMinimalEncoder, location_encoder=LocationEncoder) |
|
|
|
json=json, objective_encoder=ObjectiveMinimalEncoder, |
|
|
|
|
|
|
|
location_encoder=LocationEncoder) |
|
|
|
if role == Role.bunny: |
|
|
|
if role == Role.bunny: |
|
|
|
return render_template('game_bunny_dashboard.html', title='Game Dashboard', |
|
|
|
return render_template('game_bunny_dashboard.html', title='Game Dashboard', game=game, |
|
|
|
game=game, json=json, location_encoder=LocationEncoder) |
|
|
|
json=json, location_encoder=LocationEncoder) |
|
|
|
if role == Role.hunter: |
|
|
|
if role == Role.hunter: |
|
|
|
return render_template('game_hunter_dashboard.html', title='Game Dashboard', |
|
|
|
return render_template('game_hunter_dashboard.html', title='Game Dashboard', game=game, |
|
|
|
game=game, json=json, location_encoder=LocationEncoder) |
|
|
|
json=json, location_encoder=LocationEncoder) |
|
|
|
if role == Role.none: |
|
|
|
if role == Role.none: |
|
|
|
return render_template('game_hunter_dashboard.html', title='Game Dashboard', |
|
|
|
return render_template('game_hunter_dashboard.html', title='Game Dashboard', game=game, |
|
|
|
game=game, json=json, location_encoder=LocationEncoder) |
|
|
|
json=json, location_encoder=LocationEncoder) |
|
|
|
if role is None: |
|
|
|
if role is None: |
|
|
|
abort(403) |
|
|
|
abort(403) |
|
|
|
|
|
|
|
|
|
|
@ -152,6 +154,20 @@ def get_caught_bunny_photo_directory(game): |
|
|
|
secure_filename(game.name) / \ |
|
|
|
secure_filename(game.name) / \ |
|
|
|
current_app.config['PLAYER_CAUGHT_PLAYER_PHOTO_DIR_NAME'] |
|
|
|
current_app.config['PLAYER_CAUGHT_PLAYER_PHOTO_DIR_NAME'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/review') |
|
|
|
|
|
|
|
@login_required |
|
|
|
|
|
|
|
def review_caught_bunny_photos(game_name): |
|
|
|
|
|
|
|
game = Game.query.filter_by(name=game_name).first_or_404() |
|
|
|
|
|
|
|
if not game.owned_by(current_user): |
|
|
|
|
|
|
|
abort(403) |
|
|
|
|
|
|
|
pcp_id = request.args.get('pcp_id', default=-1, type=int) |
|
|
|
|
|
|
|
action = request.args.get('action', default='none', type=str).lower() |
|
|
|
|
|
|
|
if pcp_id != -1: |
|
|
|
|
|
|
|
pcp = PlayerCaughtPlayer.query.filter_by(id=pcp_id).first_or_404() |
|
|
|
|
|
|
|
review = Review.parse_string(action) |
|
|
|
|
|
|
|
pcp.review = review |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
return render_template('review_caught_bunny_photos.html', game=game) |
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/adduser', methods=['GET', 'POST']) |
|
|
|
@bp.route('/game/<game_name>/adduser', methods=['GET', 'POST']) |
|
|
|
@bp.route('/game/<game_name>/addplayer', methods=['GET', 'POST']) |
|
|
|
@bp.route('/game/<game_name>/addplayer', methods=['GET', 'POST']) |
|
|
@ -176,7 +192,8 @@ def add_player(game_name): |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
|
|
|
|
|
|
|
|
return render_template('add_player.html', title=f'Add User for {game_name}', form_add=form_add, form_create=form_create, game=game) |
|
|
|
return render_template('add_player.html', title=f'Add User for {game_name}', |
|
|
|
|
|
|
|
form_add=form_add, form_create=form_create, game=game) |
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/game/<game_name>/removeuser/<username>') |
|
|
|
@bp.route('/game/<game_name>/removeuser/<username>') |
|
|
|
@bp.route('/game/<game_name>/removeplayer/<username>') |
|
|
|
@bp.route('/game/<game_name>/removeplayer/<username>') |
|
|
@ -229,7 +246,8 @@ def add_objective(game_name): |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
|
flash(f"Objective has been added!") |
|
|
|
flash(f"Objective has been added!") |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=game.name)) |
|
|
|
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) |
|
|
|
return render_template('objective.html', title=f'Add Objective for {game_name}', |
|
|
|
|
|
|
|
form=form, objective=objective, owner=True) |
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/objective/<objective_hash>/delete', methods=['GET']) |
|
|
|
@bp.route('/objective/<objective_hash>/delete', methods=['GET']) |
|
|
|
@login_required |
|
|
|
@login_required |
|
|
@ -269,17 +287,18 @@ def objective(objective_hash): |
|
|
|
else: |
|
|
|
else: |
|
|
|
flash('You have already found this objective') |
|
|
|
flash('You have already found this objective') |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=objective.game.name)) |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=objective.game.name)) |
|
|
|
elif not objective.owned_by(current_user): |
|
|
|
if not objective.owned_by(current_user): |
|
|
|
flash("Only bunnies in an objective's game can find objectives!") |
|
|
|
flash("Only bunnies in an objective's game can find objectives!") |
|
|
|
abort(403) |
|
|
|
abort(403) |
|
|
|
|
|
|
|
|
|
|
|
owner = objective.owned_by(current_user) |
|
|
|
qrcode = generate_qr_code(objective) |
|
|
|
qrcode = generate_qr_code(objective) if owner else None |
|
|
|
|
|
|
|
form = ObjectiveForm() |
|
|
|
form = ObjectiveForm() |
|
|
|
if form.submit.data and form.validate() and owner: |
|
|
|
form.old_name = objective.name |
|
|
|
|
|
|
|
if form.submit.data and form.validate(): |
|
|
|
objective.name = form.objective_name.data |
|
|
|
objective.name = form.objective_name.data |
|
|
|
objective.longitude = form.longitude.data |
|
|
|
objective.longitude = form.longitude.data |
|
|
|
objective.latitude = form.latitude.data |
|
|
|
objective.latitude = form.latitude.data |
|
|
|
db.session.commit() |
|
|
|
db.session.commit() |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=objective.game.name)) |
|
|
|
return redirect(url_for('main.game_dashboard', game_name=objective.game.name)) |
|
|
|
return render_template('objective.html', title='Objective view', objective=objective, owner=owner, form=form, qrcode=qrcode) |
|
|
|
return render_template('objective.html', title='Objective view', |
|
|
|
|
|
|
|
objective=objective, owner=True, form=form, qrcode=qrcode) |
|
|
|