diff --git a/aurweb/filters.py b/aurweb/filters.py
index 9b731501..45cb6d83 100644
--- a/aurweb/filters.py
+++ b/aurweb/filters.py
@@ -2,7 +2,7 @@ import copy
import math
from datetime import datetime
-from typing import Any, Dict
+from typing import Any, Dict, Union
from urllib.parse import quote_plus, urlencode
from zoneinfo import ZoneInfo
@@ -148,3 +148,25 @@ def _quote_plus(*args, **kwargs) -> str:
@register_filter("ceil")
def ceil(*args, **kwargs) -> int:
return math.ceil(*args, **kwargs)
+
+
+@register_function("date_strftime")
+@pass_context
+def date_strftime(context: Dict[str, Any], dt: Union[int, datetime], fmt: str) \
+ -> str:
+ if isinstance(dt, int):
+ dt = timestamp_to_datetime(dt)
+ tz = context.get("timezone")
+ return as_timezone(dt, tz).strftime(fmt)
+
+
+@register_function("date_display")
+@pass_context
+def date_display(context: Dict[str, Any], dt: Union[int, datetime]) -> str:
+ return date_strftime(context, dt, "%Y-%m-%d (%Z)")
+
+
+@register_function("datetime_display")
+@pass_context
+def datetime_display(context: Dict[str, Any], dt: Union[int, datetime]) -> str:
+ return date_strftime(context, dt, "%Y-%m-%d %H:%M (%Z)")
diff --git a/templates/account/show.html b/templates/account/show.html
index 34549ff0..a9bb3c30 100644
--- a/templates/account/show.html
+++ b/templates/account/show.html
@@ -57,7 +57,7 @@
{{
"Inactive since %s" | tr
- | format(inactive_ds.strftime("%Y-%m-%d %H:%M"))
+ | format(datetime_display(inactive_ds))
}}
|
{% endif %}
@@ -66,15 +66,14 @@
{% trans %}Registration date{% endtrans %}: |
- {{ user.RegistrationTS.strftime("%Y-%m-%d") }}
+ {{ date_display(user.RegistrationTS) }}
|
{% endif %}
{% if login_ts %}
{% trans %}Last Login{% endtrans %}: |
- {% set login_ds = login_ts | dt | as_timezone(timezone) %}
- {{ login_ds.strftime("%Y-%m-%d") }} |
+ {{ date_display(login_ts) }} |
{% endif %}
diff --git a/templates/partials/account/comment.html b/templates/partials/account/comment.html
index 8c310738..f88aab02 100644
--- a/templates/partials/account/comment.html
+++ b/templates/partials/account/comment.html
@@ -17,7 +17,7 @@
username,
comment.ID
),
- commented_at.strftime("%Y-%m-%d %H:%M"),
+ datetime_display(comment.CommentTS),
""
) | safe
}}
@@ -25,7 +25,7 @@
{% set edited_on = comment.EditedTS | dt | as_timezone(timezone) %}
({{ "edited on %s by %s" | tr
- | format(edited_on.strftime('%Y-%m-%d %H:%M'),
+ | format(datetime_display(comment.EditedTS),
'%s' | format(
comment.Editor.Username, comment.Editor.Username))
| safe
diff --git a/templates/partials/packages/actions.html b/templates/partials/packages/actions.html
index 148da592..313495a3 100644
--- a/templates/partials/packages/actions.html
+++ b/templates/partials/packages/actions.html
@@ -34,10 +34,9 @@
- {% set ood_ts = pkgbase.OutOfDateTS | dt | as_timezone(timezone) %}
{{
"Flagged out-of-date (%s)"
- | tr | format(ood_ts.strftime("%Y-%m-%d"))
+ | tr | format(date_strftime(package.PackageBase.OutOfDateTS, "%Y-%m-%d"))
}}
diff --git a/templates/partials/packages/comment.html b/templates/partials/packages/comment.html
index 1427e0a0..e4818837 100644
--- a/templates/partials/packages/comment.html
+++ b/templates/partials/packages/comment.html
@@ -18,8 +18,8 @@
)) if request.user.is_authenticated() else
(comment.User.Username),
'%s' | format(
- comment.ID,
- commented_at.strftime("%Y-%m-%d %H:%M")
+ comment.ID,
+ datetime_display(comment.CommentTS)
)
)
| safe
@@ -28,7 +28,7 @@
{% set edited_on = comment.EditedTS | dt | as_timezone(timezone) %}
({{ "edited on %s by %s" | tr
- | format(edited_on.strftime('%Y-%m-%d %H:%M'),
+ | format(datetime_display(comment.EditedTS),
'%s' | format(
comment.Editor.Username, comment.Editor.Username))
| safe
diff --git a/templates/partials/packages/details.html b/templates/partials/packages/details.html
index b5193314..0c5bc3b9 100644
--- a/templates/partials/packages/details.html
+++ b/templates/partials/packages/details.html
@@ -150,14 +150,12 @@
{{ pkgbase.Popularity | number_format(6 if pkgbase.Popularity <= 0.2 else 2) }} |
- {% set submitted = pkgbase.SubmittedTS | dt | as_timezone(timezone) %}
{{ "First Submitted" | tr }}: |
- {{ "%s" | format(submitted.strftime("%Y-%m-%d %H:%M")) }} |
+ {{ datetime_display(pkgbase.SubmittedTS) }} |
{{ "Last Updated" | tr }}: |
- {% set updated = pkgbase.ModifiedTS | dt | as_timezone(timezone) %}
- {{ "%s" | format(updated.strftime("%Y-%m-%d %H:%M")) }} |
+ {{ datetime_display(pkgbase.ModifiedTS) }} |
diff --git a/templates/partials/packages/requests.html b/templates/partials/packages/requests.html
index 4084e96f..5f31515c 100644
--- a/templates/partials/packages/requests.html
+++ b/templates/partials/packages/requests.html
@@ -40,7 +40,7 @@
{{ request.User.Username }}
- {{ requested.strftime("%Y-%m-%d %H:%M") }} |
+ {{ datetime_display(request.RequestTS) }} |
{{ request.status_display() | tr }} |
{% endfor %}
diff --git a/templates/partials/packages/updates.html b/templates/partials/packages/updates.html
index 9b1996e9..767a93f6 100644
--- a/templates/partials/packages/updates.html
+++ b/templates/partials/packages/updates.html
@@ -24,8 +24,7 @@
- {% set modified = pkg.PackageBase.ModifiedTS | dt | as_timezone(timezone) %}
- {{ modified.strftime("%Y-%m-%d %H:%M") }}
+ {{ datetime_display(pkg.PackageBase.ModifiedTS) }}
|
{% endfor %}
diff --git a/templates/partials/tu/proposal/details.html b/templates/partials/tu/proposal/details.html
index fd84f093..f7a55148 100644
--- a/templates/partials/tu/proposal/details.html
+++ b/templates/partials/tu/proposal/details.html
@@ -21,15 +21,13 @@
- {% set submitted = voteinfo.Submitted | dt | as_timezone(timezone) %}
{% set submitter = voteinfo.Submitter.Username %}
{% set submitter_uri = "/account/%s" | format(submitter) %}
{% set submitter = '%s' | format(submitter_uri, submitter) %}
- {% set end = voteinfo.End | dt | as_timezone(timezone) %}
{{
"Submitted: %s by %s" | tr
- | format(submitted.strftime("%Y-%m-%d %H:%M"), submitter)
+ | format(datetime_display(voteinfo.Submitted), submitter)
| safe
}}
@@ -37,7 +35,7 @@
{{ "End" | tr }}:
- {{ end.strftime("%Y-%m-%d %H:%M") }}
+ {{ datetime_display(voteinfo.End) }}
diff --git a/templates/partials/tu/proposals.html b/templates/partials/tu/proposals.html
index 4126683a..318001b5 100644
--- a/templates/partials/tu/proposals.html
+++ b/templates/partials/tu/proposals.html
@@ -47,15 +47,8 @@
{{ agenda }}
-
- {% set submitted = result.Submitted | dt | as_timezone(timezone) %}
- {{ submitted.strftime("%Y-%m-%d") }} |
-
-
- {% set end = result.End | dt | as_timezone(timezone) %}
- {{ end.strftime("%Y-%m-%d") }} |
+ {{ date_display(result.Submitted) }} |
+ {{ date_display(result.End) }} |
{% if not result.User %}
diff --git a/templates/pkgbase/flag-comment.html b/templates/pkgbase/flag-comment.html
index 4df6ee4b..35b998d1 100644
--- a/templates/pkgbase/flag-comment.html
+++ b/templates/pkgbase/flag-comment.html
@@ -21,7 +21,7 @@
"following reason:"
| tr | format("", username, "",
"", pkgbase.Name, "",
- "", flagged_at.strftime("%Y-%m-%d"), "")
+ "", date_display(pkgbase.OutOfDateTS), "")
| safe
}}
diff --git a/templates/pkgbase/voters.html b/templates/pkgbase/voters.html
index be86f01f..d7df8b81 100644
--- a/templates/pkgbase/voters.html
+++ b/templates/pkgbase/voters.html
@@ -17,8 +17,7 @@
{{ pkg_vote.User.Username }}
- {% set voted_at = pkg_vote.VoteTS | dt | as_timezone(timezone) %}
- ({{ voted_at.strftime("%Y-%m-%d %H:%M") }})
+ ({{ datetime_display(pkg_vote.VoteTS) }})
{% endfor %}
diff --git a/templates/requests.html b/templates/requests.html
index c9e63e60..ff265de1 100644
--- a/templates/requests.html
+++ b/templates/requests.html
@@ -60,8 +60,7 @@
{% endif %}
>
{# Date #}
- {% set date = result.RequestTS | dt | as_timezone(timezone) %}
- {{ date.strftime("%Y-%m-%d %H:%M") }}
+ {{ datetime_display(result.RequestTS) }}
|
{# Status #}
diff --git a/test/test_templates.py b/test/test_templates.py
index 0d36d0b9..7d6b585c 100644
--- a/test/test_templates.py
+++ b/test/test_templates.py
@@ -258,7 +258,7 @@ def check_package_details(content: str, pkg: Package) -> None:
assert pop.text.strip() == number_format(0, 6)
# Check First Submitted
- date_fmt = "%Y-%m-%d %H:%M"
+ date_fmt = "%Y-%m-%d %H:%M (%Z)"
i += 1
first_submitted = rows[i].xpath("./td")[0]
converted_dt = as_timezone(to_dt(pkg.PackageBase.SubmittedTS), "UTC")
diff --git a/test/test_trusted_user_routes.py b/test/test_trusted_user_routes.py
index 0ea44d10..a448c043 100644
--- a/test/test_trusted_user_routes.py
+++ b/test/test_trusted_user_routes.py
@@ -16,7 +16,7 @@ from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User
from aurweb.testing.requests import Request
-DATETIME_REGEX = r'^[0-9]{4}-[0-9]{2}-[0-9]{2}$'
+DATETIME_REGEX = r'^[0-9]{4}-[0-9]{2}-[0-9]{2} \(.+\)$'
PARTICIPATION_REGEX = r'^1?[0-9]{2}[%]$' # 0% - 100%
@@ -523,7 +523,7 @@ def test_tu_running_proposal(client: TestClient,
submitted = details.xpath(
'./div[contains(@class, "submitted")]/text()')[0]
- assert re.match(r'^Submitted: \d{4}-\d{2}-\d{2} \d{2}:\d{2} by$',
+ assert re.match(r'^Submitted: \d{4}-\d{2}-\d{2} \d{2}:\d{2} \(.+\) by$',
submitted.strip()) is not None
submitter = details.xpath('./div[contains(@class, "submitted")]/a')[0]
assert submitter.text.strip() == tu_user.Username
@@ -534,7 +534,7 @@ def test_tu_running_proposal(client: TestClient,
assert end_label.strip() == "End:"
end_datetime = end.xpath("./strong/text()")[0]
- assert re.match(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
+ assert re.match(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2} \(.+\)$',
end_datetime.strip()) is not None
# We have not voted yet. Assert that our voting form is shown.
|