Code

Opened 5 years ago

Closed 5 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: UI/UX:

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 5 years ago.
patch

Download all attachments as: .zip

Change History (2)

Changed 5 years ago by anonymous

patch

comment:1 Changed 5 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #10458

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.