post.html line timestamps mirror scroll's relative_ts buckets: swap date:'g:i A' for the existing lyric_extras.relative_ts filter so same-day Lines render as 11:46 p.m., then collapse to weekday (Sat) past 24h, 07 Mar past a week, 07 Mar 2025 past a year — DRYs onto the single filter scroll already uses (no duplicated bucketing logic); same-day rendering shifts from 11:46 PM to 11:46 p.m. as a side effect of reusing the lowercase g:i a format relative_ts already standardised on — TDD
Code architected by Disco DeDisco <discodedisco@outlook.com> Git commit message Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -433,3 +433,51 @@ class SaveScrollPositionTest(TestCase):
|
|||||||
{"position": 100},
|
{"position": 100},
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
|
|
||||||
|
class PostLineRelativeTimestampTest(TestCase):
|
||||||
|
"""post.html mirrors scroll.html's bucketed `relative_ts` time rendering:
|
||||||
|
same-day Lines show a time; older ones collapse to weekday / month-day /
|
||||||
|
month-day-year. Bypasses `auto_now_add` with a queryset .update() so the
|
||||||
|
test can backdate Lines."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.owner = User.objects.create(email="owner@post-ts.io", username="owner")
|
||||||
|
self.client.force_login(self.owner)
|
||||||
|
from apps.billboard.models import Line, Post
|
||||||
|
self.Line = Line
|
||||||
|
self.post = Post.objects.create(owner=self.owner, title="Stamp")
|
||||||
|
|
||||||
|
def _backdate(self, line, **delta):
|
||||||
|
from apps.billboard.models import Line
|
||||||
|
Line.objects.filter(pk=line.pk).update(
|
||||||
|
created_at=timezone.now() - timezone.timedelta(**delta)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_recent_line_renders_clock_time(self):
|
||||||
|
self.Line.objects.create(post=self.post, text="now", author=self.owner)
|
||||||
|
response = self.client.get(reverse("billboard:view_post", args=[self.post.id]))
|
||||||
|
self.assertRegex(
|
||||||
|
response.content.decode(),
|
||||||
|
r'class="post-line-time"[^>]*>\s*\d+:\d{2}\s*[ap]\.m\.\s*<',
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_two_day_old_line_renders_weekday(self):
|
||||||
|
line = self.Line.objects.create(post=self.post, text="old", author=self.owner)
|
||||||
|
self._backdate(line, days=2)
|
||||||
|
response = self.client.get(reverse("billboard:view_post", args=[self.post.id]))
|
||||||
|
import re
|
||||||
|
m = re.search(
|
||||||
|
r'class="post-line-time"[^>]*>\s*(\w+)\s*<', response.content.decode()
|
||||||
|
)
|
||||||
|
self.assertIsNotNone(m, "no .post-line-time cell rendered")
|
||||||
|
self.assertIn(m.group(1), {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"})
|
||||||
|
|
||||||
|
def test_thirty_day_old_line_renders_day_month(self):
|
||||||
|
line = self.Line.objects.create(post=self.post, text="oldr", author=self.owner)
|
||||||
|
self._backdate(line, days=30)
|
||||||
|
response = self.client.get(reverse("billboard:view_post", args=[self.post.id]))
|
||||||
|
self.assertRegex(
|
||||||
|
response.content.decode(),
|
||||||
|
r'class="post-line-time"[^>]*>\s*\d{2}\s\w{3}\s*<',
|
||||||
|
)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
<li class="post-line {% if line.author.username == 'adman' %}post-line--system{% endif %}">
|
<li class="post-line {% if line.author.username == 'adman' %}post-line--system{% endif %}">
|
||||||
<span class="post-line-author">{{ line.author|at_handle }}</span>
|
<span class="post-line-author">{{ line.author|at_handle }}</span>
|
||||||
<span class="post-line-text">{# adman-authored Lines (note unlock + share invite system prose) carry an `<a class="note-ref">` anchor that needs to render as HTML. User-typed Lines stay escaped. #}{% if line.author.username == 'adman' %}{{ line.text|safe }}{% else %}{{ line.text }}{% endif %}</span>
|
<span class="post-line-text">{# adman-authored Lines (note unlock + share invite system prose) carry an `<a class="note-ref">` anchor that needs to render as HTML. User-typed Lines stay escaped. #}{% if line.author.username == 'adman' %}{{ line.text|safe }}{% else %}{{ line.text }}{% endif %}</span>
|
||||||
<time class="post-line-time" datetime="{{ line.created_at|date:'c' }}">{{ line.created_at|date:'g:i A' }}</time>
|
<time class="post-line-time" datetime="{{ line.created_at|date:'c' }}">{{ line.created_at|relative_ts }}</time>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="post-line-buffer" aria-hidden="true"></li>
|
<li class="post-line-buffer" aria-hidden="true"></li>
|
||||||
|
|||||||
Reference in New Issue
Block a user