Get home page and login working #14
@ -114,6 +114,6 @@ def update_logged_in(db: DbContext, username: str) -> None:
|
||||
db(
|
||||
update(User)
|
||||
.where(User.username == username)
|
||||
.values(last_login=datetime.datetime.utcnow())
|
||||
.values(last_login=datetime.datetime.now(datetime.timezone.utc))
|
||||
)
|
||||
db.session.commit()
|
||||
|
@ -1,3 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
import os
|
||||
|
||||
@ -48,6 +49,15 @@ def get_app(
|
||||
# Configure jinja options
|
||||
app.jinja_options.update(trim_blocks=True, lstrip_blocks=True)
|
||||
|
||||
def date_format(dt: datetime, formatstr="%Y-%m-%d %H:%M:%S%z") -> str:
|
||||
if dt is None:
|
||||
return "never"
|
||||
# Cast db time to UTC, then convert to local timezone
|
||||
adjusted = dt.replace(tzinfo=timezone.utc).astimezone()
|
||||
return adjusted.strftime(formatstr)
|
||||
|
||||
app.template_filter("date")(date_format)
|
||||
|
||||
# Set up Flask-Login
|
||||
auth.get_login_manager().init_app(app)
|
||||
|
||||
|
@ -21,13 +21,6 @@ def register_custom_filters(app):
|
||||
val = getattr(user.cfg, 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)
|
||||
|
||||
@app.template_filter("articlelink")
|
||||
def article_link(title):
|
||||
return url_for(
|
||||
|
@ -40,6 +40,6 @@
|
||||
<p>
|
||||
<b>{{ user.username }}</b> {% if user.username != user.display_name %} / {{ user.display_name }}{% endif %} (id #{{user.id}}){% if user.is_site_admin %} <b>[ADMIN]</b>{% endif %}
|
||||
</p>
|
||||
<p>Last activity: {{ user.last_activity }} — Last login: {{ user.last_login }}</p>
|
||||
<p>Last activity: {{ user.last_activity|date }} — Last login: {{ user.last_login|date }}</p>
|
||||
</div>
|
||||
{% endmacro %}
|
Loading…
Reference in New Issue
Block a user