Opened 15 years ago

Closed 15 years ago

#10688 closed (duplicate)

archive_month generic view next_month is incorrect

Reported by: anonymous Owned by: nobody
Component: Generic views Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This isn't an april fools day joke, I promise. However, I did notice this due to me testing my site exactly when the month changed.

django.generic.views.date_based.archive_month isn't consistent with "last_day", which makes next_month incorrect.

last_day is calculated by first_day.replace(month=first_day.month + 1). This makes last_day be the *first* day of the next month, not the last day. I think that this is necessary because if the queryset is using DateTimeField instead of DateField, it won't compare as less than the last day of the month, but will compare as less than the first day of the second month. I haven't tested that theory, though.

Anyway, next_month is then computed as last_day + timedelta(1), which is the *second* day of the month, not the first. More importantly, if it is the first of the month (as it is today), the test "last_day < datetime.date.today()" fails, causing next_month to be None when it should be valid.

The fix is quite simple: set next_month to last_day instead of last_day + timedelta(1) and change the above test to test less-than-equal instead of just less-than. Patch provided. I would also suggest refactoring last_day to something more descriptive, though.

Attachments (1)

archive_month.diff (683 bytes ) - added by anonymous 15 years ago.
patch

Download all attachments as: .zip

Change History (2)

by anonymous, 15 years ago

Attachment: archive_month.diff added

patch

comment:1 by Ramiro Morales, 15 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #10458

Note: See TracTickets for help on using tickets.
Back to Top