Human-readable dates in admin dashboard
This commit is contained in:
parent
478213f77b
commit
a0e13329a4
@ -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)
|
||||
|
@ -13,7 +13,11 @@
|
||||
|
||||
{% macro dashboard_user_item(user) %}
|
||||
<div class="dashboard-lexicon-item">
|
||||
<p><b>{{ user.username }}</b> {% if user.username != user.displayname %} / {{ user.displayname }}{% endif %} ({{user.uid}})</p>
|
||||
<p>Last activity: {{ user.last_activity }} — Last login: {{ user.last_login }}</p>
|
||||
<p>
|
||||
<b>{{ user.username }}</b>
|
||||
{% if user.username != user.displayname %} / {{ user.displayname }}{% endif %}
|
||||
({{user.uid}})
|
||||
</p>
|
||||
<p>Last activity: {{ user.last_activity|asdate }} — Last login: {{ user.last_login|asdate }}</p>
|
||||
</div>
|
||||
{% endmacro %}
|
Loading…
Reference in New Issue
Block a user