Fixed #7602 -- Corrected lookup keyword arguments in archive_month and archive_week to properly range when date_field is from DateField. Thanks nullie for the original patch and Colin Grady for the test coverage.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8476 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
264771f1b6
commit
a64dc39fb7
|
@ -129,7 +129,10 @@ def archive_month(request, year, month, queryset, date_field,
|
|||
last_day = first_day.replace(year=first_day.year + 1, month=1)
|
||||
else:
|
||||
last_day = first_day.replace(month=first_day.month + 1)
|
||||
lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
|
||||
lookup_kwargs = {
|
||||
'%s__gte' % date_field: first_day,
|
||||
'%s__lt' % date_field: last_day,
|
||||
}
|
||||
|
||||
# Only bother to check current date if the month isn't in the past and future objects are requested.
|
||||
if last_day >= now.date() and not allow_future:
|
||||
|
@ -188,7 +191,10 @@ def archive_week(request, year, week, queryset, date_field,
|
|||
# Calculate first and last day of week, for use in a date-range lookup.
|
||||
first_day = date
|
||||
last_day = date + datetime.timedelta(days=7)
|
||||
lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
|
||||
lookup_kwargs = {
|
||||
'%s__gte' % date_field: first_day,
|
||||
'%s__lt' % date_field: last_day,
|
||||
}
|
||||
|
||||
# Only bother to check current date if the week isn't in the past and future objects aren't requested.
|
||||
if last_day >= now.date() and not allow_future:
|
||||
|
|
|
@ -21,7 +21,6 @@ class BaseArticle(models.Model):
|
|||
title = models.CharField(max_length=100)
|
||||
slug = models.SlugField()
|
||||
author = models.ForeignKey(Author)
|
||||
date_created = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
@ -30,11 +29,20 @@ class BaseArticle(models.Model):
|
|||
return self.title
|
||||
|
||||
class Article(BaseArticle):
|
||||
pass
|
||||
date_created = models.DateTimeField()
|
||||
|
||||
class UrlArticle(BaseArticle):
|
||||
"""
|
||||
An Article class with a get_absolute_url defined.
|
||||
"""
|
||||
date_created = models.DateTimeField()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return '/urlarticles/%s/' % self.slug
|
||||
|
||||
class DateArticle(BaseArticle):
|
||||
"""
|
||||
An article Model with a DateField instead of DateTimeField,
|
||||
for testing #7602
|
||||
"""
|
||||
date_created = models.DateField()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from django.test import TestCase
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from regressiontests.views.models import Article, Author
|
||||
from regressiontests.views.models import Article, Author, DateArticle
|
||||
|
||||
class ObjectDetailTest(TestCase):
|
||||
fixtures = ['testdata.json']
|
||||
|
@ -68,4 +68,25 @@ class MonthArchiveTest(TestCase):
|
|||
response = self.client.get('/views/date_based/archive_month/2004/02/')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
article2 = DateArticle(title="example", author=author)
|
||||
|
||||
article2.date_created = first_second_of_feb.date()
|
||||
article2.save()
|
||||
response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
article2.date_created = (first_second_of_feb-two_seconds).date()
|
||||
article2.save()
|
||||
response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
article2.date_created = (first_second_of_mar-two_seconds).date()
|
||||
article2.save()
|
||||
response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
article2.date_created = first_second_of_mar.date()
|
||||
article2.save()
|
||||
response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
|
@ -20,6 +20,7 @@ date_based_info_dict = {
|
|||
'date_field': 'date_created',
|
||||
'month_format': '%m',
|
||||
}
|
||||
date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all())
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^$', views.index_page),
|
||||
|
@ -48,6 +49,9 @@ urlpatterns += patterns('django.views.generic.date_based',
|
|||
(r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
|
||||
'archive_month',
|
||||
date_based_info_dict),
|
||||
(r'^date_based/datefield/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
|
||||
'archive_month',
|
||||
date_based_datefield_info_dict),
|
||||
)
|
||||
|
||||
# crud generic views.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
This template intentionally left blank
|
Loading…
Reference in New Issue