From 1a289cb5c7d4ec1a9ba66ec07d1a1d5d22922d33 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sat, 25 Apr 2020 10:06:26 -0700 Subject: [PATCH] Fix a bunch of attribute references --- amanuensis/server/__init__.py | 9 ++- amanuensis/server/helpers.py | 4 +- amanuensis/server/lexicon.jinja | 14 ++--- amanuensis/server/lexicon/__init__.py | 2 +- amanuensis/server/lexicon/lexicon.join.jinja | 2 +- amanuensis/server/macros.jinja | 8 +-- amanuensis/server/session/__init__.py | 57 +++++++++---------- .../server/session/session.editor.jinja | 8 +-- ...ssion.session.jinja => session.root.jinja} | 25 ++++---- .../server/session/session.settings.jinja | 14 ++--- 10 files changed, 67 insertions(+), 76 deletions(-) rename amanuensis/server/session/{session.session.jinja => session.root.jinja} (51%) diff --git a/amanuensis/server/__init__.py b/amanuensis/server/__init__.py index 4b04664..1e799a5 100644 --- a/amanuensis/server/__init__.py +++ b/amanuensis/server/__init__.py @@ -5,7 +5,8 @@ from amanuensis.models import ModelFactory from amanuensis.server.auth import get_login_manager, bp_auth from amanuensis.server.helpers import register_custom_filters from amanuensis.server.home import bp_home -# from amanuensis.server.lexicon import bp_lexicon +from amanuensis.server.lexicon import bp_lexicon +from amanuensis.server.session import bp_session def get_app(root: RootConfigDirectoryContext) -> Flask: @@ -30,9 +31,7 @@ def get_app(root: RootConfigDirectoryContext) -> Flask: # Blueprint inits app.register_blueprint(bp_auth) app.register_blueprint(bp_home) - # app.register_blueprint(bp_lexicon) - - # import code - # code.interact(local=locals()) + app.register_blueprint(bp_lexicon) + app.register_blueprint(bp_session) return app diff --git a/amanuensis/server/helpers.py b/amanuensis/server/helpers.py index 77cfada..841d6a3 100644 --- a/amanuensis/server/helpers.py +++ b/amanuensis/server/helpers.py @@ -32,7 +32,7 @@ def register_custom_filters(app): def article_link(title): return url_for( 'lexicon.article', - name=g.lexicon.name, + name=g.lexicon.cfg.name, title=filesafe_title(title)) @@ -102,6 +102,6 @@ def editor_required(route): def editor_route(*args, **kwargs): if current_user.uid != g.lexicon.cfg.editor: flash("You must be the editor to view this page") - return redirect(url_for('lexicon.contents', name=g.lexicon.name)) + return redirect(url_for('lexicon.contents', name=g.lexicon.cfg.name)) return route(*args, **kwargs) return editor_route diff --git a/amanuensis/server/lexicon.jinja b/amanuensis/server/lexicon.jinja index 3bcee3f..0431219 100644 --- a/amanuensis/server/lexicon.jinja +++ b/amanuensis/server/lexicon.jinja @@ -1,13 +1,9 @@ {% extends "page_2col.jinja" %} -{% if g.lexicon.title %} {% set lexicon_title = g.lexicon.title %} -{% else %} -{% set lexicon_title = "Lexicon " + g.lexicon.name %} -{% endif %} {% block header %}

{{ lexicon_title }}

-

{{ g.lexicon.prompt }}

+

{{ g.lexicon.cfg.prompt }}

{% endblock %} {% block sb_logo %}{% endblock %} @@ -15,19 +11,19 @@ {% endblock %} {% block sb_contents %}Contents{% endblock %} {% block sb_rules %}Rules{% endblock %} {% block sb_session %}Session{% endblock %} {% block sb_stats %}Statistics{% endblock %} {% set template_sidebar_rows = [ diff --git a/amanuensis/server/lexicon/__init__.py b/amanuensis/server/lexicon/__init__.py index 0c7d40b..f75f449 100644 --- a/amanuensis/server/lexicon/__init__.py +++ b/amanuensis/server/lexicon/__init__.py @@ -39,7 +39,7 @@ def join(name): # Gate on join validity if player_can_join_lexicon(current_user, g.lexicon, form.password.data): add_player_to_lexicon(current_user, g.lexicon) - return redirect(url_for("lexicon.contents", name=name)) # SESSION + return redirect(url_for('session.session', name=name)) else: flash("Could not join game") return redirect(url_for("home.home", name=name)) diff --git a/amanuensis/server/lexicon/lexicon.join.jinja b/amanuensis/server/lexicon/lexicon.join.jinja index 5f22f08..7f33e6a 100644 --- a/amanuensis/server/lexicon/lexicon.join.jinja +++ b/amanuensis/server/lexicon/lexicon.join.jinja @@ -5,7 +5,7 @@
{{ form.hidden_tag() }} - {% if g.lexicon.join.password %} + {% if g.lexicon.cfg.join.password %}

{{ form.password.label }}
{{ form.password(size=32) }}

{% endif %}

{{ form.submit() }}

diff --git a/amanuensis/server/macros.jinja b/amanuensis/server/macros.jinja index 7fd248a..9cbf0b0 100644 --- a/amanuensis/server/macros.jinja +++ b/amanuensis/server/macros.jinja @@ -2,8 +2,8 @@

- {# #} - Lexicon {{ lexicon.cfg.name }}{# #} + + Lexicon {{ lexicon.cfg.name }} [{{ lexicon.status.capitalize() }}]

@@ -23,9 +23,9 @@ {% else %} Players: {{ lexicon.cfg.join.joined|count }}/{{ lexicon.cfg.join.max_players }} {% if lexicon.cfg.join.public and lexicon.cfg.join.open %} - {# / #} + / Join game - {# #} + {% endif %} {% endif %}

diff --git a/amanuensis/server/session/__init__.py b/amanuensis/server/session/__init__.py index 8adec1b..8da40ec 100644 --- a/amanuensis/server/session/__init__.py +++ b/amanuensis/server/session/__init__.py @@ -10,38 +10,30 @@ from flask import ( flash, request, Markup) -from flask_login import login_required, current_user +from flask_login import current_user -from amanuensis.config import root -from amanuensis.config.loader import ReadOnlyOrderedDict from amanuensis.errors import MissingConfigError -from amanuensis.lexicon.manage import ( - valid_add, - add_player, - add_character, +from amanuensis.lexicon import ( attempt_publish) from amanuensis.parser import ( parse_raw_markdown, PreviewHtmlRenderer, - FeatureCounter, - filesafe_title) + FeatureCounter) from amanuensis.server.forms import ( LexiconConfigForm, - LexiconJoinForm, LexiconCharacterForm, LexiconReviewForm) from amanuensis.server.helpers import ( lexicon_param, player_required, - editor_required, - player_required_if_not_public) + editor_required) def jsonfmt(obj): return Markup(json.dumps(obj)) -bp_session = Blueprint('lexicon', __name__, +bp_session = Blueprint('session', __name__, url_prefix='/lexicon//session', template_folder='.') @@ -60,10 +52,15 @@ def session(name): drafts.append(draft) if draft.status.approved: approved.append(draft) + characters = [] + for char in g.lexicon.cfg.character.values(): + if char.player == current_user.uid: + characters.append(char) return render_template( - 'session.session.jinja', + 'session.root.jinja', ready_articles=drafts, - approved_articles=approved) + approved_articles=approved, + characters=characters) def edit_character(name, form, cid): @@ -82,7 +79,7 @@ def edit_character(name, form, cid): def create_character(name, form): if form.validate_on_submit(): # On POST, verify character can be added - if not g.lexicon.can_add_character(current_user.id): + if not g.lexicon.can_add_character(current_user.uid): flash('Operation not permitted') return redirect(url_for('session.session', name=name)) # Add the character @@ -103,11 +100,11 @@ def character(name): form = LexiconCharacterForm() cid = request.args.get('cid') if cid: - if cid not in g.lexicon.character: + if cid not in g.lexicon.cfg.character: flash('Character not found') return redirect(url_for('session.session', name=name)) - if (g.lexicon.character.get(cid).player != current_user.id - and g.lexicon.editor != current_user.id): + if (g.lexicon.cfg.character.get(cid).player != current_user.uid + and g.lexicon.cfg.editor != current_user.uid): flash('Access denied') return redirect(url_for('session.session', name=name)) return edit_character(name, form, cid) @@ -164,13 +161,13 @@ def review(name): if form.approved.data == 'Y': draft.status.ready = True draft.status.approved = True - g.lexicon.add_log(f"Article '{draft.title}' approved ({draft.aid})") - if g.lexicon.publish.asap: + g.lexicon.log(f"Article '{draft.title}' approved ({draft.aid})") + if g.lexicon.cfg.publish.asap: attempt_publish(g.lexicon) else: draft.status.ready = False draft.status.approved = False - g.lexicon.add_log(f"Article '{draft.title}' rejected ({draft.aid})") + g.lexicon.log(f"Article '{draft.title}' rejected ({draft.aid})") return redirect(url_for('session.session', name=name)) # If the article was already reviewed and this is just the preview @@ -198,11 +195,11 @@ def editor(name): # Character not specified, load all characters and articles # and return render_template characters = [ - char for char in g.lexicon.character.values() - if char.player == current_user.id + char for char in g.lexicon.cfg.character.values() + if char.player == current_user.uid ] articles = [ - article for article in g.lexicon.get_drafts_for_player(uid=current_user.id) + article for article in g.lexicon.get_drafts_for_player(uid=current_user.uid) if any([article.character == char.cid for char in characters]) ] return render_template( @@ -211,12 +208,12 @@ def editor(name): articles=articles, jsonfmt=jsonfmt) - character = g.lexicon.character.get(cid) + character = g.lexicon.cfg.character.get(cid) if not character: # Character was specified, but id was invalid flash("Character not found") return redirect(url_for('session.session', name=name)) - if character.player != current_user.id: + if character.player != current_user.uid: # Player doesn't control this character flash("Access forbidden") return redirect(url_for('session.session', name=name)) @@ -226,7 +223,7 @@ def editor(name): # Character specified but not article, load character articles # and retuen r_t articles = [ - article for article in g.lexicon.get_drafts_for_player(uid=current_user.id) + article for article in g.lexicon.get_drafts_for_player(uid=current_user.uid) if article.character == character.cid ] return render_template( @@ -257,11 +254,11 @@ def editor_new(name): new_aid = uuid.uuid4().hex # TODO harden this cid = request.args.get("cid") - character = g.lexicon.character.get(cid) + character = g.lexicon.cfg.character.get(cid) article = { "version": "0", "aid": new_aid, - "lexicon": g.lexicon.id, + "lexicon": g.lexicon.lid, "character": cid, "title": "", "turn": 1, diff --git a/amanuensis/server/session/session.editor.jinja b/amanuensis/server/session/session.editor.jinja index b47c52a..07f663b 100644 --- a/amanuensis/server/session/session.editor.jinja +++ b/amanuensis/server/session/session.editor.jinja @@ -11,7 +11,7 @@