From a0e13329a43e98590d8904e1207e9cbd7152155a Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Wed, 29 Jan 2020 23:18:33 -0800 Subject: [PATCH] Human-readable dates in admin dashboard --- amanuensis/server/helpers.py | 12 +++++++++++- amanuensis/templates/macros.html | 8 ++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/amanuensis/server/helpers.py b/amanuensis/server/helpers.py index 59f334b..3bdbf64 100644 --- a/amanuensis/server/helpers.py +++ b/amanuensis/server/helpers.py @@ -1,4 +1,5 @@ # Standard library imports +from datetime import datetime from functools import wraps # Third party imports @@ -12,12 +13,21 @@ 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): + def get_user_attr(uid, attr): user = UserModel.by(uid=uid) val = getattr(user, attr) 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): """Wrapper for loading a route's lexicon""" @wraps(route) diff --git a/amanuensis/templates/macros.html b/amanuensis/templates/macros.html index c68e154..ba85281 100644 --- a/amanuensis/templates/macros.html +++ b/amanuensis/templates/macros.html @@ -13,7 +13,11 @@ {% macro dashboard_user_item(user) %}
-

{{ user.username }} {% if user.username != user.displayname %} / {{ user.displayname }}{% endif %} ({{user.uid}})

-

Last activity: {{ user.last_activity }} — Last login: {{ user.last_login }}

+

+ {{ user.username }} + {% if user.username != user.displayname %} / {{ user.displayname }}{% endif %} + ({{user.uid}}) +

+

Last activity: {{ user.last_activity|asdate }} — Last login: {{ user.last_login|asdate }}

{% endmacro %} \ No newline at end of file