Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 2efb4757af8c6d6a757779e68671c1455dde95b6 1 parent 3498849
Russell Keith-Magee authored November 23, 2010
9  django/views/generic/dates.py
@@ -348,9 +348,14 @@ def get_dated_items(self):
348 348
         week = self.get_week()
349 349
 
350 350
         date_field = self.get_date_field()
  351
+        week_format = self.get_week_format()
  352
+        week_start = {
  353
+            '%W': '1',
  354
+            '%U': '0',
  355
+        }[week_format]
351 356
         date = _date_from_string(year, self.get_year_format(),
352  
-                                 '0', '%w',
353  
-                                 week, self.get_week_format())
  357
+                                 week_start, '%w',
  358
+                                 week, week_format)
354 359
 
355 360
         # Construct a date-range lookup.
356 361
         first_day = date
11  tests/regressiontests/generic_views/dates.py
@@ -232,6 +232,16 @@ def test_week_view_invalid_pattern(self):
232 232
         res = self.client.get('/dates/books/2007/week/no_week/')
233 233
         self.assertEqual(res.status_code, 404)
234 234
 
  235
+    def test_week_start_Monday(self):
  236
+        # Regression for #14752
  237
+        res = self.client.get('/dates/books/2008/week/39/')
  238
+        self.assertEqual(res.status_code, 200)
  239
+        self.assertEqual(res.context['week'], datetime.date(2008, 9, 28))
  240
+
  241
+        res = self.client.get('/dates/books/2008/week/39/monday/')
  242
+        self.assertEqual(res.status_code, 200)
  243
+        self.assertEqual(res.context['week'], datetime.date(2008, 9, 29))
  244
+
235 245
 class DayArchiveViewTests(TestCase):
236 246
     fixtures = ['generic-views-test-data.json']
237 247
     urls = 'regressiontests.generic_views.urls'
@@ -349,4 +359,3 @@ def test_date_detail_allow_future(self):
349 359
 
350 360
     def test_invalid_url(self):
351 361
         self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/")
352  
-
2  tests/regressiontests/generic_views/tests.py
@@ -2,4 +2,4 @@
2 2
 from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests
3 3
 from regressiontests.generic_views.detail import DetailViewTest
4 4
 from regressiontests.generic_views.edit import CreateViewTests, UpdateViewTests, DeleteViewTests
5  
-from regressiontests.generic_views.list import ListViewTests
  5
+from regressiontests.generic_views.list import ListViewTests
2  tests/regressiontests/generic_views/urls.py
@@ -149,6 +149,8 @@
149 149
         views.BookWeekArchive.as_view(allow_future=True)),
150 150
     (r'^dates/books/(?P<year>\d{4})/week/no_week/$',
151 151
         views.BookWeekArchive.as_view()),
  152
+    (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/monday/$',
  153
+        views.BookWeekArchive.as_view(week_format='%W')),
152 154
 
153 155
     # DayArchiveView
154 156
     (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/$',

0 notes on commit 2efb475

Please sign in to comment.
Something went wrong with that request. Please try again.