Skip to content

Comments

Fix #2626: Duplicate scheduled year for single day events#2934

Open
iampujan wants to merge 1 commit intopython:mainfrom
iampujan:feature/issue-2626-duplicate-event-year
Open

Fix #2626: Duplicate scheduled year for single day events#2934
iampujan wants to merge 1 commit intopython:mainfrom
iampujan:feature/issue-2626-duplicate-event-year

Conversation

@iampujan
Copy link
Contributor

Fixes #2626. Removed duplicate render for dt_start|date:"Y" in time_tag.html when single_day is true. Includes a unit test to enforce single-year rendering for same 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.
Copilot AI review requested due to automatic review settings February 22, 2026 09:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes duplicate year rendering for single-day events in the shared events time tag template, and adds a unit test intended to prevent regressions (Issue #2626).

Changes:

  • Remove duplicate dt_start|date:"Y" rendering in time_tag.html when next_time.single_day is true.
  • Add a template-focused unit test to assert single-year rendering for single-day future-year events.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/events/templates/events/includes/time_tag.html Removes the extra year <span> in the single-day rendering path.
apps/events/tests/test_templates.py Adds a new test to validate the single-day template doesn’t duplicate the year.
Comments suppressed due to low confidence (2)

apps/events/tests/test_templates.py:32

  • next_time.dt_start/dt_end are timezone-aware datetimes in normal operation (model fields use timezone.now() and managers call convert_dt_to_aware). Here the mock uses naive datetime.datetime(...), which can lead to inconsistent output depending on timezone settings. Consider using django.utils.timezone.make_aware(...) (or tzinfo=datetime.UTC) for the mock datetimes to match production behavior.
                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

apps/events/tests/test_templates.py:51

  • The assertion counts year occurrences by splitting on an exact whitespace/indentation pattern. This is brittle (minor template formatting changes will break the test) and doesn’t actually verify “visible” vs attribute text robustly. Prefer parsing the rendered HTML (e.g., BeautifulSoup) and asserting the year appears exactly once as a text node within the span#start-..., or use a whitespace-tolerant regex like >\s*YEAR\s*</span>.
        # 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        </span>")
        self.assertEqual(
            len(visible_occurrences) - 1,
            1,
            f"Expected the visible span containing {year_str} to appear exactly once, but it was duplicated: {rendered}"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

from django.template.loader import render_to_string
from django.test import TestCase

from ..models import Event, EventLocation, Calendar
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses a relative import (from ..models ...), but the repo’s Ruff config bans all relative imports (flake8-tidy-imports). This will fail lint; switch to absolute imports (e.g., from apps.events.models import ...). Also EventLocation is imported but unused, which will trigger F401.

Suggested change
from ..models import Event, EventLocation, Calendar
from apps.events.models import Event, Calendar

Copilot uses AI. Check for mistakes.
# 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")
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calendar.slug is a required field (non-null, non-blank). Creating a Calendar with only name will raise an integrity/validation error when the test runs. Provide a unique slug (and optionally creator like other tests do).

Suggested change
calendar = Calendar.objects.create(name="Test Calendar")
calendar = Calendar.objects.create(
name="Test Calendar",
slug="test-calendar-time-tag-single-day-event",
)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate scheduled year for single day events whose scheduled year is rendered

1 participant