From e0dabb4904e828bfd6acfcd8efd07fa74cc42edc Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Tue, 19 Dec 2023 11:55:10 +0000 Subject: [PATCH] Fix error when rendering dates for events They were coming out as `%s`. --- .../events/templatetags/spectator_events.py | 2 +- tests/events/test_templatetags.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spectator/events/templatetags/spectator_events.py b/spectator/events/templatetags/spectator_events.py index b03e031..60e215d 100644 --- a/spectator/events/templatetags/spectator_events.py +++ b/spectator/events/templatetags/spectator_events.py @@ -69,7 +69,7 @@ def display_date(d): stamp = d.strftime("%Y-%m-%d") visible_date = d.strftime(app_settings.DATE_FORMAT) - return format_html('', stamp, visible_date) + return format_html('', stamp, visible_date) @register.inclusion_tag("spectator_events/includes/event_list_tabs.html") diff --git a/tests/events/test_templatetags.py b/tests/events/test_templatetags.py index 797443c..225cbee 100644 --- a/tests/events/test_templatetags.py +++ b/tests/events/test_templatetags.py @@ -1,3 +1,5 @@ +from datetime import datetime, timezone + from django.test import TestCase from spectator.core.factories import IndividualCreatorFactory @@ -16,6 +18,7 @@ annual_event_counts, day_events, day_events_card, + display_date, event_list_tabs, events_years, events_years_card, @@ -58,6 +61,20 @@ def test_kind(self): self.assertEqual(qs[1], {"year": make_date("2018-01-01"), "total": 1}) +class DisplayDateTestCase(TestCase): + def test_date(self): + d = make_date("2023-12-09") + self.assertEqual( + display_date(d), '' + ) + + def test_datetime(self): + dt = datetime(2023, 12, 9, 13, 30, 00).astimezone(timezone.utc) + self.assertEqual( + display_date(dt), '' + ) + + class EventListTabsTestCase(TestCase): def test_result(self): counts = {"all": 30, "gig": 12, "movie": 18}