Add user list to dashboard lexicon display

This commit is contained in:
Tim Van Baak 2020-01-26 22:18:52 -08:00
parent 817e74f6d7
commit aaac4b6568
4 changed files with 17 additions and 11 deletions

View File

@ -6,6 +6,7 @@ from flask_login import LoginManager
from amanuensis.config import get from amanuensis.config import get
from amanuensis.server.auth import get_bp as get_auth_bp from amanuensis.server.auth import get_bp as get_auth_bp
from amanuensis.server.home import get_bp as get_home_bp from amanuensis.server.home import get_bp as get_home_bp
from amanuensis.server.helpers import register_custom_filters
from amanuensis.server.lexicon import get_bp as get_lex_bp from amanuensis.server.lexicon import get_bp as get_lex_bp
# Flask app init # Flask app init
@ -14,6 +15,7 @@ app = Flask(__name__, template_folder="../templates", static_folder=static_root)
app.secret_key = bytes.fromhex(get('secret_key')) app.secret_key = bytes.fromhex(get('secret_key'))
app.jinja_options['trim_blocks'] = True app.jinja_options['trim_blocks'] = True
app.jinja_options['lstrip_blocks'] = True app.jinja_options['lstrip_blocks'] = True
register_custom_filters(app)
# Flask-Login init # Flask-Login init
login = LoginManager(app) login = LoginManager(app)

View File

@ -7,6 +7,16 @@ from flask_login import current_user
# Module imports # Module imports
from amanuensis.lexicon import LexiconModel from amanuensis.lexicon import LexiconModel
from amanuensis.user import UserModel
def register_custom_filters(app):
"""Adds custom filters to the Flask app"""
@app.template_filter("user_attr")
def user_attr(uid, attr):
user = UserModel.by(uid=uid)
val = getattr(user, attr)
return val
def lexicon_param(route): def lexicon_param(route):
"""Wrapper for loading a route's lexicon""" """Wrapper for loading a route's lexicon"""
@ -19,6 +29,7 @@ def lexicon_param(route):
return route(name) return route(name)
return with_lexicon return with_lexicon
def admin_required(route): def admin_required(route):
"""Requires the user to be an admin to load this page""" """Requires the user to be an admin to load this page"""
@wraps(route) @wraps(route)
@ -29,6 +40,7 @@ def admin_required(route):
return route(*args, **kwargs) return route(*args, **kwargs)
return admin_route return admin_route
def player_required(route): def player_required(route):
"""Requires the user to be a player in the lexicon to load this page""" """Requires the user to be a player in the lexicon to load this page"""
@wraps(route) @wraps(route)

View File

@ -1,4 +1,5 @@
{% extends "page_1col.html" %} {% extends "page_1col.html" %}
{% import 'macros.html' as macros %}
{% block title %}Home | Amanuensis{% endblock %} {% block title %}Home | Amanuensis{% endblock %}
{% block header %}<h2>Amanuensis - Home</h2>{% endblock %} {% block header %}<h2>Amanuensis - Home</h2>{% endblock %}
@ -15,17 +16,7 @@
<h2>Your games</h2> <h2>Your games</h2>
{% if lexicons %} {% if lexicons %}
{% for lexicon in lexicons %} {% for lexicon in lexicons %}
{{ macros.dashboard_lexicon_item(lexicon) }}
<div class="dashboard-lexicon-item dashboard-lexicon-{{ lexicon.status() }}">
<p>
<span class="dashboard-lexicon-item-title">
<a href="{{ url_for('lexicon.session', name=lexicon.name) }}">Lexicon {{ lexicon.name }}</a>
</span>
[{{ lexicon.status().capitalize() }}]
</p>
<p><i>{{ lexicon.prompt }}</i></p>
</div>
{% endfor %} {% endfor %}
{% else %} {% else %}
<p>You haven't joined a game yet.</p> <p>You haven't joined a game yet.</p>

View File

@ -7,6 +7,7 @@
[{{ lexicon.status().capitalize() }}] [{{ lexicon.status().capitalize() }}]
</p> </p>
<p><i>{{ lexicon.prompt }}</i></p> <p><i>{{ lexicon.prompt }}</i></p>
<p>Editor: {{ lexicon.editor|user_attr('username') }} / Players: {% for uid in lexicon.join.joined[:-1] %}{{ uid|user_attr('username') }}, {% endfor %}{{ lexicon.join.joined[-1]|user_attr('username') }}</p>
</div> </div>
{% endmacro %} {% endmacro %}