#10688: archive_month generic view next_month is incorrect
---------------------------+------------------------------------------------
 Reporter:  anonymous      |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Generic views  |     Version:  1.0       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  1              |  
---------------------------+------------------------------------------------
 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.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10688>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to