From 1f1465de6b226332017b251a629df930f691ab0b Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Wed, 29 Apr 2020 21:55:07 -0700 Subject: [PATCH] Predicate some UI elements on game state --- amanuensis/server/helpers.py | 9 ++++++++- amanuensis/server/lexicon/__init__.py | 5 +++++ amanuensis/server/session/session.root.jinja | 8 ++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/amanuensis/server/helpers.py b/amanuensis/server/helpers.py index 841d6a3..a533ea1 100644 --- a/amanuensis/server/helpers.py +++ b/amanuensis/server/helpers.py @@ -8,7 +8,7 @@ from flask_login import current_user # Module imports from amanuensis.parser import filesafe_title -from amanuensis.models import ModelFactory, UserModel +from amanuensis.models import ModelFactory, UserModel, LexiconModel def register_custom_filters(app): @@ -35,6 +35,13 @@ def register_custom_filters(app): name=g.lexicon.cfg.name, title=filesafe_title(title)) + @app.context_processor + def lexicon_status(): + return dict( + PREGAME=LexiconModel.PREGAME, + ONGOING=LexiconModel.ONGOING, + COMPLETE=LexiconModel.COMPLETE) + def lexicon_param(route): """Wrapper for loading a route's lexicon""" diff --git a/amanuensis/server/lexicon/__init__.py b/amanuensis/server/lexicon/__init__.py index 32d5b31..74bedfa 100644 --- a/amanuensis/server/lexicon/__init__.py +++ b/amanuensis/server/lexicon/__init__.py @@ -9,6 +9,7 @@ from flask import ( from flask_login import login_required, current_user from amanuensis.lexicon import player_can_join_lexicon, add_player_to_lexicon +from amanuensis.models import LexiconModel from amanuensis.parser import filesafe_title from amanuensis.server.helpers import ( lexicon_param, @@ -26,6 +27,10 @@ bp_lexicon = Blueprint('lexicon', __name__, @lexicon_param @login_required def join(name): + if g.lexicon.status != LexiconModel.PREGAME: + flash("Can't join a game already in progress") + return redirect(url_for('home.home')) + if not g.lexicon.cfg.join.open: flash("This game isn't open for joining") return redirect(url_for('home.home')) diff --git a/amanuensis/server/session/session.root.jinja b/amanuensis/server/session/session.root.jinja index 7b8785d..3ff3789 100644 --- a/amanuensis/server/session/session.root.jinja +++ b/amanuensis/server/session/session.root.jinja @@ -36,12 +36,14 @@ {% endfor %} +{% if g.lexicon.status == ONGOING %} {% if publish_form %}
{{ publish_form.hidden_tag() }}

{{ publish_form.submit() }}

{% endif %} +{% endif %} {% endblock %} {% set template_content_blocks = template_content_blocks + [self.bl_editor()] %} {% endif %} @@ -60,18 +62,20 @@ {% endfor %} {% - if characters|count is lt(g.lexicon.cfg.join.chars_per_player) - and not g.lexicon.cfg.turn.current + if g.lexicon.status == PREGAME + and characters|count is lt(g.lexicon.cfg.join.chars_per_player) %}
  • Create a character
  • {% endif %} + {% if g.lexicon.status == ONGOING %}
  • Article editor
  • + {% endif %} {% endblock %} {% set template_content_blocks = template_content_blocks + [self.main()] %} \ No newline at end of file