Opened 8 days ago

Closed 8 days ago

#35994 closed Bug (invalid)

WeekArchiveView sometimes gets the next week year wrong in the last week of the year

Reported by: Nigel Metheringham Owned by:
Component: Generic views Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In some cases - for example ISO or Monday start weeks in 2024, the last week of the year has the next week set as week 1 of 2024, and not week 1 of 2025.

Sample code:

class TicketScheduleWeekView(WeekArchiveView):
    """View of tickets scheduled for a week."""

    # queryset = ## Queryset deleted as its quite large
    date_field = "date"
    week_format = "%W"
    year_format = "%Y"
    allow_future = True
    allow_empty = True

Given the following URL definition:

path("ticketschedule/<int:year>/<int:week>/", views.TicketScheduleWeekView.as_view(), name="ticket-schedule-week"), 

We get for end of year links:-

  • /ticketschedule/2023/51/ - next week link is /ticketschedule/2023/52/
  • /ticketschedule/2024/52/ - next week link is /ticketschedule/2024/1/
  • /ticketschedule/2024/51/ - next week link is /ticketschedule/2024/52/
  • /ticketschedule/2024/52/ - next week link is /ticketschedule/2024/1/ wrong

Change History (1)

comment:1 by Nigel Metheringham, 8 days ago

Resolution: invalid
Status: newclosed

Apologies. When looking deeper into this I discovered that I had the following in the template:-

        <li class="page-item">
          <a class="page-link"
             href="{% url 'ticket-schedule-week' next_week.year next_week.isocalendar.week %}">Next &raquo;</a>
        </li>

when it should have been

        <li class="page-item">
          <a class="page-link"
             href="{% url 'ticket-schedule-week' next_week.isocalendar.year next_week.isocalendar.week %}">Next &raquo;</a>
        </li>
Note: See TracTickets for help on using tickets.
Back to Top