new core.middleware sets cookie for scroll timestamp view to local browser time, w. new corresponding tests in core.tests.UTs.test_middleware; apps.lyric.templatetags.lyric_extras determines timestamp format based on duration elapsed since timestamp; apps.bill.tests.ITs.test_views renamed, now also asserts scroll renders event body and time in columns
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Disco DeDisco
2026-04-02 14:51:08 -04:00
parent 2a7d4c7410
commit 8538f76b13
11 changed files with 192 additions and 5 deletions

View File

@@ -143,6 +143,11 @@ class BillscrollViewTest(TestCase):
response = self.client.get(f"/billboard/room/{self.room.id}/scroll/")
self.assertEqual(response.context["scroll_position"], 250)
def test_scroll_renders_event_body_and_time_columns(self):
response = self.client.get(f"/billboard/room/{self.room.id}/scroll/")
self.assertContains(response, 'class="drama-event-body"')
self.assertContains(response, 'class="drama-event-time"')
class SaveScrollPositionTest(TestCase):
def setUp(self):

View File

@@ -1,4 +1,5 @@
from django import template
from django.utils import dateformat, timezone
register = template.Library()
@@ -17,6 +18,29 @@ def truncate_email(email):
return local + "@" + domain_name + "." + domain_tld
@register.filter
def relative_ts(dt):
"""Return a compact relative timestamp string for a datetime value.
< 24 h → "3:07 a.m."
< 7 d → "Thu"
< 1 y → "07 Mar"
≥ 1 y → "07 Mar 2025"
"""
if dt is None:
return ""
local_dt = timezone.localtime(dt)
diff = timezone.now() - dt
if diff.total_seconds() < 86400:
return dateformat.format(local_dt, "g:i a")
elif diff.days < 7:
return dateformat.format(local_dt, "D")
elif diff.days < 365:
return dateformat.format(local_dt, "d M")
else:
return dateformat.format(local_dt, "d M Y")
@register.filter
def display_name(user):
if user is None: