From 56c8f01199ae8ab116a0909d8ac1cfdbe7c6ee14 Mon Sep 17 00:00:00 2001 From: Pujan Thapa Date: Sun, 22 Feb 2026 10:02:05 +0100 Subject: [PATCH 1/3] Fix #2626: Duplicate scheduled year for single day events - Removes redundant rendering of next_time.dt_start year block inside time_tag.html for single_day events - Adds unit tests to ensure the DOM output for single day events generates the year precisely once. --- .../templates/events/includes/time_tag.html | 4 -- apps/events/tests/test_templates.py | 52 +++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 apps/events/tests/test_templates.py diff --git a/apps/events/templates/events/includes/time_tag.html b/apps/events/templates/events/includes/time_tag.html index 90bc4491b..cfeeb9f7a 100644 --- a/apps/events/templates/events/includes/time_tag.html +++ b/apps/events/templates/events/includes/time_tag.html @@ -4,10 +4,6 @@ {{ next_time.dt_start|date:"Y" }} - - {{ next_time.dt_start|date:"Y" }} - - {% if not next_time.all_day %} {{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }} {% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }} diff --git a/apps/events/tests/test_templates.py b/apps/events/tests/test_templates.py new file mode 100644 index 000000000..a2ab572e9 --- /dev/null +++ b/apps/events/tests/test_templates.py @@ -0,0 +1,52 @@ +import datetime + +from django.template.loader import render_to_string +from django.test import TestCase + +from ..models import Event, EventLocation, Calendar + + +class TimeTagTemplateTests(TestCase): + def test_single_day_event_year_rendering(self): + """ + Verify that a single-day event does not render the year twice (Issue #2626). + """ + # Create a single day event in the future to trigger the year rendering condition + future_year = datetime.date.today().year + 1 + + calendar = Calendar.objects.create(name="Test Calendar") + + event = Event.objects.create( + title="Single Day Future Event", + description="Test event", + calendar=calendar, + ) + + # Manually create the next_time context object + class MockTime: + def __init__(self): + self.dt_start = datetime.datetime(future_year, 5, 25, 12, 0) + self.dt_end = datetime.datetime(future_year, 5, 25, 14, 0) + self.single_day = True + self.all_day = False + self.valid_dt_end = True + + context = { + "next_time": MockTime(), + "scheduled_start_this_year": False, # Event is in the future year + "scheduled_end_this_year": False, + "object": event, + } + + rendered = render_to_string("events/includes/time_tag.html", context) + + # The year should only appear visibly once in the output (not counting the datetime ISO tag). + year_str = str(future_year) + # Using string splitting to exclude the `datetime="2027...` occurrence by checking how many times + # it appears wrapped with whitespace or inside a span. + visible_occurrences = rendered.split(">\n " + year_str + "\n ") + self.assertEqual( + len(visible_occurrences) - 1, + 1, + f"Expected the visible span containing {year_str} to appear exactly once, but it was duplicated: {rendered}" + ) From 270125b36b9fa231edff4f8b2a5a24fbab74e439 Mon Sep 17 00:00:00 2001 From: Pujan Thapa Date: Tue, 24 Feb 2026 10:20:25 +0100 Subject: [PATCH 2/3] Update apps/events/tests/test_templates.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- apps/events/tests/test_templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/events/tests/test_templates.py b/apps/events/tests/test_templates.py index a2ab572e9..978c6841a 100644 --- a/apps/events/tests/test_templates.py +++ b/apps/events/tests/test_templates.py @@ -3,7 +3,7 @@ from django.template.loader import render_to_string from django.test import TestCase -from ..models import Event, EventLocation, Calendar +from apps.events.models import Event, Calendar class TimeTagTemplateTests(TestCase): From 8d9db16d409996b5e4c4f232ea3d9f306b5202ca Mon Sep 17 00:00:00 2001 From: Pujan Thapa Date: Tue, 24 Feb 2026 10:20:50 +0100 Subject: [PATCH 3/3] Update apps/events/tests/test_templates.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- apps/events/tests/test_templates.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/events/tests/test_templates.py b/apps/events/tests/test_templates.py index 978c6841a..51cee3514 100644 --- a/apps/events/tests/test_templates.py +++ b/apps/events/tests/test_templates.py @@ -14,7 +14,10 @@ def test_single_day_event_year_rendering(self): # Create a single day event in the future to trigger the year rendering condition future_year = datetime.date.today().year + 1 - calendar = Calendar.objects.create(name="Test Calendar") + calendar = Calendar.objects.create( + name="Test Calendar", + slug="test-calendar-time-tag-single-day-event", + ) event = Event.objects.create( title="Single Day Future Event",