Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#17192 closed Bug (fixed)

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

Reported by: justin@… Owned by: aaugustin
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


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

# in
from django.db import models

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

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

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, 11, 9), not None.

Attachments (1)

next_day_17192.diff (3.4 KB) - added by pbnan 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by julien

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Looking at the code, the bug is most likely here:

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

comment:2 Changed 5 years ago by julien

The problem appears to be in the old-style generic view too:
Even though it is deprecated, it is still supported and so it should be fixed as well.

comment:3 Changed 4 years ago by pbnan

  • Owner changed from nobody to pbnan

Changed 4 years ago by pbnan

comment:4 Changed 4 years ago by pbnan

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 Changed 4 years ago by aaugustin

  • Owner changed from pbnan to aaugustin

comment:6 Changed 4 years ago by aaugustin

  • Resolution set to fixed
  • Status changed from new to closed

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

I'm going to add a regression test anyway.

comment:7 Changed 4 years ago by Aymeric Augustin <aymeric.augustin@…>

In [ab268e18486b244f6633f2e013c12b6664a3661a]:

Added a test for DayArchiveView. Refs #17192.

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