Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#17192 closed Bug (fixed)

next_day from views.generic.dates.DayArchiveView returns None instead of today

Reported by: justin@… Owned by: Aymeric Augustin
Component: Generic views Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The next_day from views.generic.dates.DayArchiveView returns None when next_day would be today.

# in models.py
from django.db import models

class Post(models.Model):  
  pub_date = models.DateTimeField(auto_now_add=True)

# views.py
from django.views import generic
from bugdemo.models import *

class PostDayView(generic.DayArchiveView):
  queryset = Post.objects.all()
  date_field = 'pub_date'
  allow_empty = True
  allow_future = False

# urls.py
from django.conf.urls.defaults import patterns, include, url
from bugdemo.views import PostDayView

urlpatterns = patterns('',
  (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/$', PostDayView.as_view()),
)

# post_archive_day.html
Previous day: {{ previous_day }}
Next day: {{ next_day }}

# page request
$ curl http://localhost:8000/2011/nov/9/    # that's yesterday, as of the time of writing
Previous day: Nov. 8, 2011
Next day: None

Unless I misunderstand what the behavior is supposed to be, I expected the next_day to be datetime.date(2011, 11, 9), not None.

Attachments (1)

next_day_17192.diff (3.4 KB ) - added by Piotr Banaszkiewicz 12 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Julien Phalip, 12 years ago

Triage Stage: UnreviewedAccepted

Looking at the code, the bug is most likely here: https://code.djangoproject.com/browser/django/trunk/django/views/generic/dates.py?rev=16974#L586

The condition should be a "less than or equal".

comment:2 by Julien Phalip, 12 years ago

The problem appears to be in the old-style generic view too: https://code.djangoproject.com/browser/django/trunk/django/views/generic/date_based.py?rev=15989#L283
Even though it is deprecated, it is still supported and so it should be fixed as well.

comment:3 by Piotr Banaszkiewicz, 12 years ago

Owner: changed from nobody to Piotr Banaszkiewicz

by Piotr Banaszkiewicz, 12 years ago

Attachment: next_day_17192.diff added

comment:4 by Piotr Banaszkiewicz, 12 years ago

I've done some tests and it appears that in elder generic views this particular bug is not present, although it certainly is for the new-style generic views.
I've included patch for it.

comment:5 by Aymeric Augustin, 12 years ago

Owner: changed from Piotr Banaszkiewicz to Aymeric Augustin

comment:6 by Aymeric Augustin, 12 years ago

Resolution: fixed
Status: newclosed

This was fixed as a side effect of the rewrite in 20e697368219603599649bc67aea5e087caedeae.

I'm going to add a regression test anyway.

comment:7 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

In [ab268e18486b244f6633f2e013c12b6664a3661a]:

Added a test for DayArchiveView. Refs #17192.

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