Human-readable dates in admin dashboard

This commit is contained in:
Tim Van Baak 2020-01-29 23:18:33 -08:00
parent 478213f77b
commit a0e13329a4
2 changed files with 17 additions and 3 deletions

View File

@ -1,4 +1,5 @@
# Standard library imports # Standard library imports
from datetime import datetime
from functools import wraps from functools import wraps
# Third party imports # Third party imports
@ -12,12 +13,21 @@ from amanuensis.user import UserModel
def register_custom_filters(app): def register_custom_filters(app):
"""Adds custom filters to the Flask app""" """Adds custom filters to the Flask app"""
@app.template_filter("user_attr") @app.template_filter("user_attr")
def user_attr(uid, attr): def get_user_attr(uid, attr):
user = UserModel.by(uid=uid) user = UserModel.by(uid=uid)
val = getattr(user, attr) val = getattr(user, attr)
return val return val
@app.template_filter("asdate")
def timestamp_to_readable(ts, formatstr="%Y-%m-%d %H:%M:%S"):
if ts is None:
return "null"
dt = datetime.fromtimestamp(ts)
return dt.strftime(formatstr)
def lexicon_param(route): def lexicon_param(route):
"""Wrapper for loading a route's lexicon""" """Wrapper for loading a route's lexicon"""
@wraps(route) @wraps(route)

View File

@ -13,7 +13,11 @@
{% macro dashboard_user_item(user) %} {% macro dashboard_user_item(user) %}
<div class="dashboard-lexicon-item"> <div class="dashboard-lexicon-item">
<p><b>{{ user.username }}</b> {% if user.username != user.displayname %} / {{ user.displayname }}{% endif %} ({{user.uid}})</p> <p>
<p>Last activity: {{ user.last_activity }} &mdash; Last login: {{ user.last_login }}</p> <b>{{ user.username }}</b>
{% if user.username != user.displayname %} / {{ user.displayname }}{% endif %}
({{user.uid}})
</p>
<p>Last activity: {{ user.last_activity|asdate }} &mdash; Last login: {{ user.last_login|asdate }}</p>
</div> </div>
{% endmacro %} {% endmacro %}