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.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

View File

@ -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

View File

@ -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 %}
<h2>{{ lexicon_title }}</h2>
<p><i>{{ g.lexicon.prompt }}</i></p>
<p><i>{{ g.lexicon.cfg.prompt }}</i></p>
{% endblock %}
{% block sb_logo %}{% endblock %}
@ -15,19 +11,19 @@
{% endblock %}
{% block sb_contents %}<a
{% 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 %}
{% block sb_rules %}<a
{% 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 %}
{% block sb_session %}<a
{% 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 %}
{% block sb_stats %}<a
{% 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 %}
{% set template_sidebar_rows = [

View File

@ -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))

View File

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

View File

@ -2,8 +2,8 @@
<div class="dashboard-lexicon-item dashboard-lexicon-{{ lexicon.status }}">
<p>
<span class="dashboard-lexicon-item-title">
{# <a href="{{ url_for('lexicon.contents', name=lexicon.cfg.name) }}"> #}
Lexicon {{ lexicon.cfg.name }}{# </a> #}
<a href="{{ url_for('lexicon.contents', name=lexicon.cfg.name) }}">
Lexicon {{ lexicon.cfg.name }}</a>
</span>
[{{ lexicon.status.capitalize() }}]
</p>
@ -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 %}
{# / <a href="{{ url_for('lexicon.join', name=lexicon.cfg.name) }}"> #}
/ <a href="{{ url_for('lexicon.join', name=lexicon.cfg.name) }}">
Join game
{# </a> #}
</a>
{% endif %}
{% endif %}
</p>

View File

@ -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/<name>/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,

View File

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

View File

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

View File

@ -3,16 +3,16 @@
{% block info %}
<p>
Id: {{ g.lexicon.id }}<br>
Name: {{ g.lexicon.name }}<br>
Created: {{ g.lexicon.time.created|asdate }}<br>
Completed: {{ g.lexicon.time.completed|asdate }}<br>
Id: {{ g.lexicon.lid }}<br>
Name: {{ g.lexicon.cfg.name }}<br>
Created: {{ g.lexicon.cfg.time.created|asdate }}<br>
Completed: {{ g.lexicon.cfg.time.completed|asdate }}<br>
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 %}
{% endfor %}<br>
Characters:
{% for char in g.lexicon.character.values() %}
{% for char in g.lexicon.cfg.character.values() %}
{{ char.name }}{% if char.player %}
({{ char.player|user_attr('username') }}){% endif %}
{% if not loop.last %},{% endif %}
@ -20,7 +20,7 @@
</p>
<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;">
{% for log_entry in g.lexicon.log %}
{% for log_entry in g.lexicon.cfg.log %}
[{{ log_entry[0]|asdate }}] {{ log_entry[1] }}<br>
{% endfor %}
</div>