Code

Opened 2 years ago

Closed 2 years ago

Last modified 2 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

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 pbnan 2 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 2 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: 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 Changed 2 years ago by julien

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 Changed 2 years ago by pbnan

  • Owner changed from nobody to pbnan

Changed 2 years ago by pbnan

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

  • Owner changed from pbnan to aaugustin

comment:6 Changed 2 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 2 years ago by Aymeric Augustin <aymeric.augustin@…>

In [ab268e18486b244f6633f2e013c12b6664a3661a]:

Added a test for DayArchiveView. Refs #17192.

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.