Browse Source

implement find objective

testing
Burathar 4 years ago
parent
commit
4161ae5d40
  1. 18
      app/main/routes.py
  2. 4
      app/templates/objective.html

18
app/main/routes.py

@ -255,6 +255,24 @@ def objective_qrcode(objective_hash):
@login_required @login_required
def objective(objective_hash): def objective(objective_hash):
objective = Objective.query.filter_by(hash=objective_hash).first_or_404() objective = Objective.query.filter_by(hash=objective_hash).first_or_404()
if current_user.role_in_game(objective.game) == Role.bunny:
player = current_user.player_in(objective.game)
if not objective in player.found_objectives:
player.found_objectives.append(objective)
db.session.commit()
if objective.name:
flash(f'You found objective: {objective.name}!')
else:
flash('You found an objective!')
elif objective.name:
flash(f"You have already found objective '{objective.name}'")
else:
flash('You have already found this objective')
return redirect(url_for('main.game_dashboard', game_name=objective.game.name))
elif not objective.owned_by(current_user):
flash("Only bunnies in an objective's game can find objectives!")
abort(403)
owner = objective.owned_by(current_user) owner = objective.owned_by(current_user)
qrcode = generate_qr_code(objective) if owner else None qrcode = generate_qr_code(objective) if owner else None
form = ObjectiveForm() form = ObjectiveForm()

4
app/templates/objective.html

@ -42,7 +42,9 @@
</div> </div>
{% if objective.hash %} {% if objective.hash %}
<div class="row"> <div class="row">
<img src="{{ url_for('main.objective_qrcode', objective_hash=objective.hash) }}" alt="qr_code_failed", width="100%"> <a href="{{ url_for('main.objective', objective_hash=objective.hash) }}">
<img src="{{ url_for('main.objective_qrcode', objective_hash=objective.hash) }}" alt="qr_code_failed", width="100%">
</a>
</div> </div>
{% endif %} {% endif %}
{% else %} {% else %}

Loading…
Cancel
Save