mirror of https://github.com/django/django.git
Fixed #14752 -- Corrected date parsing in WeekArchiveView when using %W as a week format. Thanks to msundstr for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14684 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3498849532
commit
2efb4757af
|
@ -348,9 +348,14 @@ class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView):
|
||||||
week = self.get_week()
|
week = self.get_week()
|
||||||
|
|
||||||
date_field = self.get_date_field()
|
date_field = self.get_date_field()
|
||||||
|
week_format = self.get_week_format()
|
||||||
|
week_start = {
|
||||||
|
'%W': '1',
|
||||||
|
'%U': '0',
|
||||||
|
}[week_format]
|
||||||
date = _date_from_string(year, self.get_year_format(),
|
date = _date_from_string(year, self.get_year_format(),
|
||||||
'0', '%w',
|
week_start, '%w',
|
||||||
week, self.get_week_format())
|
week, week_format)
|
||||||
|
|
||||||
# Construct a date-range lookup.
|
# Construct a date-range lookup.
|
||||||
first_day = date
|
first_day = date
|
||||||
|
|
|
@ -232,6 +232,16 @@ class WeekArchiveViewTests(TestCase):
|
||||||
res = self.client.get('/dates/books/2007/week/no_week/')
|
res = self.client.get('/dates/books/2007/week/no_week/')
|
||||||
self.assertEqual(res.status_code, 404)
|
self.assertEqual(res.status_code, 404)
|
||||||
|
|
||||||
|
def test_week_start_Monday(self):
|
||||||
|
# Regression for #14752
|
||||||
|
res = self.client.get('/dates/books/2008/week/39/')
|
||||||
|
self.assertEqual(res.status_code, 200)
|
||||||
|
self.assertEqual(res.context['week'], datetime.date(2008, 9, 28))
|
||||||
|
|
||||||
|
res = self.client.get('/dates/books/2008/week/39/monday/')
|
||||||
|
self.assertEqual(res.status_code, 200)
|
||||||
|
self.assertEqual(res.context['week'], datetime.date(2008, 9, 29))
|
||||||
|
|
||||||
class DayArchiveViewTests(TestCase):
|
class DayArchiveViewTests(TestCase):
|
||||||
fixtures = ['generic-views-test-data.json']
|
fixtures = ['generic-views-test-data.json']
|
||||||
urls = 'regressiontests.generic_views.urls'
|
urls = 'regressiontests.generic_views.urls'
|
||||||
|
@ -349,4 +359,3 @@ class DateDetailViewTests(TestCase):
|
||||||
|
|
||||||
def test_invalid_url(self):
|
def test_invalid_url(self):
|
||||||
self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/")
|
self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/")
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,8 @@ urlpatterns = patterns('',
|
||||||
views.BookWeekArchive.as_view(allow_future=True)),
|
views.BookWeekArchive.as_view(allow_future=True)),
|
||||||
(r'^dates/books/(?P<year>\d{4})/week/no_week/$',
|
(r'^dates/books/(?P<year>\d{4})/week/no_week/$',
|
||||||
views.BookWeekArchive.as_view()),
|
views.BookWeekArchive.as_view()),
|
||||||
|
(r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/monday/$',
|
||||||
|
views.BookWeekArchive.as_view(week_format='%W')),
|
||||||
|
|
||||||
# DayArchiveView
|
# DayArchiveView
|
||||||
(r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/$',
|
(r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/$',
|
||||||
|
|
Loading…
Reference in New Issue