From aaac4b65681543659fdd3458e580736a1e36f23e Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sun, 26 Jan 2020 22:18:52 -0800 Subject: [PATCH] Add user list to dashboard lexicon display --- amanuensis/server/__init__.py | 2 ++ amanuensis/server/helpers.py | 12 ++++++++++++ amanuensis/templates/home/home.html | 13 ++----------- amanuensis/templates/macros.html | 1 + 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/amanuensis/server/__init__.py b/amanuensis/server/__init__.py index 7c6b8b7..eb88b87 100644 --- a/amanuensis/server/__init__.py +++ b/amanuensis/server/__init__.py @@ -6,6 +6,7 @@ from flask_login import LoginManager from amanuensis.config import get 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.helpers import register_custom_filters from amanuensis.server.lexicon import get_bp as get_lex_bp # 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.jinja_options['trim_blocks'] = True app.jinja_options['lstrip_blocks'] = True +register_custom_filters(app) # Flask-Login init login = LoginManager(app) diff --git a/amanuensis/server/helpers.py b/amanuensis/server/helpers.py index f25ea95..1dd3ba7 100644 --- a/amanuensis/server/helpers.py +++ b/amanuensis/server/helpers.py @@ -7,6 +7,16 @@ from flask_login import current_user # Module imports 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): """Wrapper for loading a route's lexicon""" @@ -19,6 +29,7 @@ def lexicon_param(route): return route(name) return with_lexicon + def admin_required(route): """Requires the user to be an admin to load this page""" @wraps(route) @@ -29,6 +40,7 @@ def admin_required(route): return route(*args, **kwargs) return admin_route + def player_required(route): """Requires the user to be a player in the lexicon to load this page""" @wraps(route) diff --git a/amanuensis/templates/home/home.html b/amanuensis/templates/home/home.html index 2022688..5b2b82f 100644 --- a/amanuensis/templates/home/home.html +++ b/amanuensis/templates/home/home.html @@ -1,4 +1,5 @@ {% extends "page_1col.html" %} +{% import 'macros.html' as macros %} {% block title %}Home | Amanuensis{% endblock %} {% block header %}

Amanuensis - Home

{% endblock %} @@ -15,17 +16,7 @@

Your games

{% if lexicons %} {% for lexicon in lexicons %} - -
-

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

-

{{ lexicon.prompt }}

-
- +{{ macros.dashboard_lexicon_item(lexicon) }} {% endfor %} {% else %}

You haven't joined a game yet.

diff --git a/amanuensis/templates/macros.html b/amanuensis/templates/macros.html index 9a41554..c68e154 100644 --- a/amanuensis/templates/macros.html +++ b/amanuensis/templates/macros.html @@ -7,6 +7,7 @@ [{{ lexicon.status().capitalize() }}]

{{ lexicon.prompt }}

+

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') }}

{% endmacro %}