Add user list to dashboard lexicon display
This commit is contained in:
parent
817e74f6d7
commit
aaac4b6568
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% extends "page_1col.html" %}
|
||||
{% import 'macros.html' as macros %}
|
||||
{% block title %}Home | Amanuensis{% endblock %}
|
||||
{% block header %}<h2>Amanuensis - Home</h2>{% endblock %}
|
||||
|
||||
|
@ -15,17 +16,7 @@
|
|||
<h2>Your games</h2>
|
||||
{% if lexicons %}
|
||||
{% for lexicon in lexicons %}
|
||||
|
||||
<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>
|
||||
|
||||
{{ macros.dashboard_lexicon_item(lexicon) }}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>You haven't joined a game yet.</p>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
[{{ lexicon.status().capitalize() }}]
|
||||
</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>
|
||||
{% endmacro %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue