add timestamp macro

This commit is contained in:
Lera Elvoé 2025-06-30 17:11:24 +03:00
parent a95200caf9
commit 19bf98f5b5
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
5 changed files with 16 additions and 5 deletions

View File

@ -7,6 +7,7 @@ from .constants import (
PermissionLevel, PermissionLevel,
InfoboxKind, InfoboxIcons, InfoboxHTMLClass InfoboxKind, InfoboxIcons, InfoboxHTMLClass
) )
from datetime import datetime
import os import os
import time import time
import secrets import secrets
@ -92,4 +93,8 @@ def create_app():
def inject_auth(): def inject_auth():
return {"is_logged_in": is_logged_in, "get_active_user": get_active_user, "active_user": get_active_user()} return {"is_logged_in": is_logged_in, "get_active_user": get_active_user, "active_user": get_active_user()}
@app.template_filter("ts_datetime")
def ts_datetime(ts, format):
return datetime.utcfromtimestamp(ts).strftime(format)
return app return app

View File

@ -25,4 +25,5 @@
</footer> </footer>
<script src="/static/js/copy-code.js"></script> <script src="/static/js/copy-code.js"></script>
<script src="/static/js/ui.js"></script> <script src="/static/js/ui.js"></script>
<script src="/static/js/date-fmt.js"></script>
</body> </body>

View File

@ -38,3 +38,7 @@
</span> </span>
</div> </div>
{% endmacro %} {% endmacro %}
{% macro timestamp(unix_ts) %}
<span class="timestamp" data-utc="{{ unix_ts }}">{{ unix_ts | ts_datetime('%Y-%m-%d %H:%M')}} ST</span>
{% endmacro %}

View File

@ -1,4 +1,4 @@
{% from 'common/macros.html' import pager %} {% from 'common/macros.html' import pager, timestamp %}
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}browsing topic {{ topic['name'] }}{% endblock %} {% block title %}browsing topic {{ topic['name'] }}{% endblock %}
{% block content %} {% block content %}
@ -30,11 +30,11 @@
<span> <span>
<span class="thread-title"><a href="{{ url_for("threads.thread", slug=thread['slug']) }}">{{thread['title']}}</a></span> <span class="thread-title"><a href="{{ url_for("threads.thread", slug=thread['slug']) }}">{{thread['title']}}</a></span>
&bullet; &bullet;
Started by <a href="{{ url_for("users.page", username=thread['started_by']) }}">{{ thread['started_by'] }}</a> on ... Started by <a href="{{ url_for("users.page", username=thread['started_by']) }}">{{ thread['started_by'] }}</a> on {{ timestamp(thread['created_at'])}}
</span> </span>
<span> <span>
Latest post by <a href="{{ url_for("users.page", username=thread['latest_post_username']) }}">{{ thread['latest_post_username'] }}</a> Latest post by <a href="{{ url_for("users.page", username=thread['latest_post_username']) }}">{{ thread['latest_post_username'] }}</a>
on ... on <a href="{{ url_for("threads.thread", slug=thread['slug']) }}">on {{ timestamp(thread['latest_post_created_at'] )}}</a>:
</span> </span>
<span class="thread-info-post-preview"> <span class="thread-info-post-preview">
{{ thread['latest_post_content'] }} {{ thread['latest_post_content'] }}

View File

@ -1,3 +1,4 @@
{% from 'common/macros.html' import timestamp %}
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}{{ target_user.username }}'s profile{% endblock %} {% block title %}{{ target_user.username }}'s profile{% endblock %}
{% block content %} {% block content %}
@ -17,9 +18,9 @@
{% if active_user and active_user.is_mod() and not target_user.is_system() %} {% if active_user and active_user.is_mod() and not target_user.is_system() %}
<h1 class="thread-title">Moderation controls</h1> <h1 class="thread-title">Moderation controls</h1>
{% if target_user.is_guest() %} {% if target_user.is_guest() %}
<p>This user is a guest. They signed up on ... </p> <p>This user is a guest. They signed up on {{ timestamp(target_user['created_at']) }}</p>
{% else %} {% else %}
<p>This user signed up on ... and was confirmed on ...</p> <p>This user signed up on {{ timestamp(target_user['created_at']) }} and was confirmed on {{ timestamp(target_user['confirmed_on']) }}</p>
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>