Fix a bunch of attribute references

This commit is contained in:
Tim Van Baak 2020-04-25 10:06:26 -07:00
parent 4fc5f80538
commit 1a289cb5c7
10 changed files with 67 additions and 76 deletions

View File

@ -5,7 +5,8 @@ from amanuensis.models import ModelFactory
from amanuensis.server.auth import get_login_manager, bp_auth from amanuensis.server.auth import get_login_manager, bp_auth
from amanuensis.server.helpers import register_custom_filters from amanuensis.server.helpers import register_custom_filters
from amanuensis.server.home import bp_home 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: def get_app(root: RootConfigDirectoryContext) -> Flask:
@ -30,9 +31,7 @@ def get_app(root: RootConfigDirectoryContext) -> Flask:
# Blueprint inits # Blueprint inits
app.register_blueprint(bp_auth) app.register_blueprint(bp_auth)
app.register_blueprint(bp_home) app.register_blueprint(bp_home)
# app.register_blueprint(bp_lexicon) app.register_blueprint(bp_lexicon)
app.register_blueprint(bp_session)
# import code
# code.interact(local=locals())
return app return app

View File

@ -32,7 +32,7 @@ def register_custom_filters(app):
def article_link(title): def article_link(title):
return url_for( return url_for(
'lexicon.article', 'lexicon.article',
name=g.lexicon.name, name=g.lexicon.cfg.name,
title=filesafe_title(title)) title=filesafe_title(title))
@ -102,6 +102,6 @@ def editor_required(route):
def editor_route(*args, **kwargs): def editor_route(*args, **kwargs):
if current_user.uid != g.lexicon.cfg.editor: if current_user.uid != g.lexicon.cfg.editor:
flash("You must be the editor to view this page") 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 route(*args, **kwargs)
return editor_route return editor_route

View File

@ -1,13 +1,9 @@
{% extends "page_2col.jinja" %} {% extends "page_2col.jinja" %}
{% if g.lexicon.title %}
{% set lexicon_title = g.lexicon.title %} {% set lexicon_title = g.lexicon.title %}
{% else %}
{% set lexicon_title = "Lexicon " + g.lexicon.name %}
{% endif %}
{% block header %} {% block header %}
<h2>{{ lexicon_title }}</h2> <h2>{{ lexicon_title }}</h2>
<p><i>{{ g.lexicon.prompt }}</i></p> <p><i>{{ g.lexicon.cfg.prompt }}</i></p>
{% endblock %} {% endblock %}
{% block sb_logo %}{% endblock %} {% block sb_logo %}{% endblock %}
@ -15,19 +11,19 @@
{% endblock %} {% endblock %}
{% block sb_contents %}<a {% block sb_contents %}<a
{% if current_page == "contents" %}class="current-page" {% if current_page == "contents" %}class="current-page"
{% else %}href="{{ url_for('lexicon.contents', name=g.lexicon.name) }}" {% else %}href="{{ url_for('lexicon.contents', name=g.lexicon.cfg.name) }}"
{% endif %}>Contents</a>{% endblock %} {% endif %}>Contents</a>{% endblock %}
{% block sb_rules %}<a {% block sb_rules %}<a
{% if current_page == "rules" %}class="current-page" {% if current_page == "rules" %}class="current-page"
{% else %}href="{{ url_for('lexicon.rules', name=g.lexicon.name) }}" {% else %}href="{{ url_for('lexicon.rules', name=g.lexicon.cfg.name) }}"
{% endif %}>Rules</a>{% endblock %} {% endif %}>Rules</a>{% endblock %}
{% block sb_session %}<a {% block sb_session %}<a
{% if current_page == "session" %}class="current-page" {% if current_page == "session" %}class="current-page"
{% else %}href="{{ url_for('lexicon.session', name=g.lexicon.name) }}" {% else %}href="{{ url_for('session.session', name=g.lexicon.cfg.name) }}"
{% endif %}>Session</a>{% endblock %} {% endif %}>Session</a>{% endblock %}
{% block sb_stats %}<a {% block sb_stats %}<a
{% if current_page == "statistics" %}class="current-page" {% if current_page == "statistics" %}class="current-page"
{% else %}href="{{ url_for('lexicon.stats', name=g.lexicon.name) }}" {% else %}href="{{ url_for('lexicon.stats', name=g.lexicon.cfg.name) }}"
{% endif %}>Statistics</a>{% endblock %} {% endif %}>Statistics</a>{% endblock %}
{% set template_sidebar_rows = [ {% set template_sidebar_rows = [

View File

@ -39,7 +39,7 @@ def join(name):
# Gate on join validity # Gate on join validity
if player_can_join_lexicon(current_user, g.lexicon, form.password.data): if player_can_join_lexicon(current_user, g.lexicon, form.password.data):
add_player_to_lexicon(current_user, g.lexicon) 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: else:
flash("Could not join game") flash("Could not join game")
return redirect(url_for("home.home", name=name)) return redirect(url_for("home.home", name=name))

View File

@ -5,7 +5,7 @@
<form id="lexicon-join" action="" method="post" novalidate> <form id="lexicon-join" action="" method="post" novalidate>
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{% if g.lexicon.join.password %} {% if g.lexicon.cfg.join.password %}
<p>{{ form.password.label }}<br>{{ form.password(size=32) }}</p> <p>{{ form.password.label }}<br>{{ form.password(size=32) }}</p>
{% endif %} {% endif %}
<p>{{ form.submit() }}</p> <p>{{ form.submit() }}</p>

View File

@ -2,8 +2,8 @@
<div class="dashboard-lexicon-item dashboard-lexicon-{{ lexicon.status }}"> <div class="dashboard-lexicon-item dashboard-lexicon-{{ lexicon.status }}">
<p> <p>
<span class="dashboard-lexicon-item-title"> <span class="dashboard-lexicon-item-title">
{# <a href="{{ url_for('lexicon.contents', name=lexicon.cfg.name) }}"> #} <a href="{{ url_for('lexicon.contents', name=lexicon.cfg.name) }}">
Lexicon {{ lexicon.cfg.name }}{# </a> #} Lexicon {{ lexicon.cfg.name }}</a>
</span> </span>
[{{ lexicon.status.capitalize() }}] [{{ lexicon.status.capitalize() }}]
</p> </p>
@ -23,9 +23,9 @@
{% else %} {% else %}
Players: {{ lexicon.cfg.join.joined|count }}/{{ lexicon.cfg.join.max_players }} Players: {{ lexicon.cfg.join.joined|count }}/{{ lexicon.cfg.join.max_players }}
{% if lexicon.cfg.join.public and lexicon.cfg.join.open %} {% if lexicon.cfg.join.public and lexicon.cfg.join.open %}
{# / <a href="{{ url_for('lexicon.join', name=lexicon.cfg.name) }}"> #} / <a href="{{ url_for('lexicon.join', name=lexicon.cfg.name) }}">
Join game Join game
{# </a> #} </a>
{% endif %} {% endif %}
{% endif %} {% endif %}
</p> </p>

View File

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

View File

@ -11,7 +11,7 @@
<link rel="stylesheet" href="{{ url_for('static', filename='editor.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='editor.css') }}">
<script> <script>
params = { params = {
updateURL: "{{ url_for('lexicon.editor_update', name=g.lexicon.name) }}", updateURL: "{{ url_for('session.editor_update', name=g.lexicon.cfg.name) }}",
{% if character %} {% if character %}
character: {{ jsonfmt(character) }}, character: {{ jsonfmt(character) }},
{% else %} {% else %}
@ -31,7 +31,7 @@
<div id="editor-left" class="column"> <div id="editor-left" class="column">
<div class="contentblock"> <div class="contentblock">
<div id="editor-header"> <div id="editor-header">
<a href="{{ url_for('lexicon.session', name=g.lexicon.name) }}"> <a href="{{ url_for('session.session', name=g.lexicon.cfg.name) }}">
{{ g.lexicon.title }} {{ g.lexicon.title }}
</a> </a>
{% if article and not article.status.approved %} {% if article and not article.status.approved %}
@ -53,7 +53,7 @@
{% for article in articles %} {% for article in articles %}
{% if article.character == char.cid %} {% if article.character == char.cid %}
<li> <li>
<a href="{{ url_for('lexicon.editor', name=g.lexicon.name, cid=char.cid, aid=article.aid) }}">{{ article.title if article.title.strip() else "Untitled" }}</a> <a href="{{ url_for('session.editor', name=g.lexicon.cfg.name, cid=char.cid, aid=article.aid) }}">{{ article.title if article.title.strip() else "Untitled" }}</a>
<span> <span>
{% if not article.status.ready %} {% if not article.status.ready %}
[Draft] [Draft]
@ -67,7 +67,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<li> <li>
<a href="{{ url_for('lexicon.editor_new', name=g.lexicon.name, cid=char.cid) }}"> <a href="{{ url_for('session.editor_new', name=g.lexicon.cfg.name, cid=char.cid) }}">
New New
</a> </a>
</li> </li>

View File

@ -4,24 +4,24 @@
{% set template_content_blocks = [] %} {% set template_content_blocks = [] %}
{% if current_user.id == g.lexicon.editor %} {% if current_user.uid == g.lexicon.cfg.editor %}
{% block bl_editor %} {% block bl_editor %}
<p>Editor actions</p> <p>Editor actions</p>
<ul> <ul>
<li> <li>
<a href="{{ url_for('lexicon.settings', name=g.lexicon.name) }}"> <a href="{{ url_for('session.settings', name=g.lexicon.cfg.name) }}">
Edit lexicon settings Edit lexicon settings
</a> </a>
</li> </li>
<li> <li>
<a href="{{ url_for('lexicon.character', name=g.lexicon.name, cid='default') }}"> <a href="{{ url_for('session.character', name=g.lexicon.cfg.name, cid='default') }}">
Edit default character Edit default character
</a> </a>
</li> </li>
{% for article in ready_articles %} {% for article in ready_articles %}
<li> <li>
<a href="{{ url_for('lexicon.review', name=g.lexicon.name, aid=article.aid) }}"> <a href="{{ url_for('session.review', name=g.lexicon.cfg.name, aid=article.aid) }}">
Review <i>{{ article.title }}</i> by {{ g.lexicon.character[article.character].name }} Review <i>{{ article.title }}</i> by {{ g.lexicon.cfg.character[article.character].name }}
</a> </a>
</li> </li>
{% endfor %} {% endfor %}
@ -30,8 +30,8 @@
<ul> <ul>
{% for article in approved_articles %} {% for article in approved_articles %}
<li> <li>
<a href="{{ url_for('lexicon.review', name=g.lexicon.name, aid=article.aid) }}"> <a href="{{ url_for('session.review', name=g.lexicon.cfg.name, aid=article.aid) }}">
<i>{{ article.title }}</i> by {{ g.lexicon.character[article.character].name }} <i>{{ article.title }}</i> by {{ g.lexicon.cfg.character[article.character].name }}
</a> </a>
</li> </li>
{% endfor %} {% endfor %}
@ -46,24 +46,23 @@
{% endfor %} {% endfor %}
<p>Player actions</p> <p>Player actions</p>
<ul> <ul>
{% set characters = g.lexicon.get_characters_for_player(current_user.id) %}
{% for char in characters %} {% for char in characters %}
<li> <li>
<a href="{{ url_for('lexicon.character', name=g.lexicon.name, cid=char.cid) }}"> <a href="{{ url_for('session.character', name=g.lexicon.cfg.name, cid=char.cid) }}">
Edit {{ char.name }} Edit {{ char.name }}
</a> </a>
</li> </li>
{% endfor %} {% endfor %}
{% {%
if characters|count is lt(g.lexicon.join.chars_per_player) if characters|count is lt(g.lexicon.cfg.join.chars_per_player)
and not g.lexicon.turn.current and not g.lexicon.cfg.turn.current
%} %}
<li> <li>
<a href="{{ url_for('lexicon.character', name=g.lexicon.name) }}">Create a character</a> <a href="{{ url_for('session.character', name=g.lexicon.cfg.name) }}">Create a character</a>
</li> </li>
{% endif %} {% endif %}
<li> <li>
<a href="{{ url_for('lexicon.editor', name=g.lexicon.name) }}"> <a href="{{ url_for('session.editor', name=g.lexicon.cfg.name) }}">
Article editor Article editor
</a> </a>
</li> </li>

View File

@ -3,16 +3,16 @@
{% block info %} {% block info %}
<p> <p>
Id: {{ g.lexicon.id }}<br> Id: {{ g.lexicon.lid }}<br>
Name: {{ g.lexicon.name }}<br> Name: {{ g.lexicon.cfg.name }}<br>
Created: {{ g.lexicon.time.created|asdate }}<br> Created: {{ g.lexicon.cfg.time.created|asdate }}<br>
Completed: {{ g.lexicon.time.completed|asdate }}<br> Completed: {{ g.lexicon.cfg.time.completed|asdate }}<br>
Players: Players:
{% for uid in g.lexicon.join.joined %} {% for uid in g.lexicon.cfg.join.joined %}
{{ uid|user_attr('username') }}{% if not loop.last %},{% endif %} {{ uid|user_attr('username') }}{% if not loop.last %},{% endif %}
{% endfor %}<br> {% endfor %}<br>
Characters: Characters:
{% for char in g.lexicon.character.values() %} {% for char in g.lexicon.cfg.character.values() %}
{{ char.name }}{% if char.player %} {{ char.name }}{% if char.player %}
({{ char.player|user_attr('username') }}){% endif %} ({{ char.player|user_attr('username') }}){% endif %}
{% if not loop.last %},{% endif %} {% if not loop.last %},{% endif %}
@ -20,7 +20,7 @@
</p> </p>
<div style="width: 100%; height: 10em; overflow-y:auto; resize: vertical; <div style="width: 100%; height: 10em; overflow-y:auto; resize: vertical;
border: 1px solid #bbbbbb; font-size: 0.7em; padding:3px; box-sizing: border-box;"> border: 1px solid #bbbbbb; font-size: 0.7em; padding:3px; box-sizing: border-box;">
{% for log_entry in g.lexicon.log %} {% for log_entry in g.lexicon.cfg.log %}
[{{ log_entry[0]|asdate }}] {{ log_entry[1] }}<br> [{{ log_entry[0]|asdate }}] {{ log_entry[1] }}<br>
{% endfor %} {% endfor %}
</div> </div>