diff --git a/django/views/generic/dates.py b/django/views/generic/dates.py index cbc7bfc065e..8c952495936 100644 --- a/django/views/generic/dates.py +++ b/django/views/generic/dates.py @@ -348,9 +348,14 @@ class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView): week = self.get_week() 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(), - '0', '%w', - week, self.get_week_format()) + week_start, '%w', + week, week_format) # Construct a date-range lookup. first_day = date diff --git a/tests/regressiontests/generic_views/dates.py b/tests/regressiontests/generic_views/dates.py index c730c763b95..c583d0ba608 100644 --- a/tests/regressiontests/generic_views/dates.py +++ b/tests/regressiontests/generic_views/dates.py @@ -232,6 +232,16 @@ class WeekArchiveViewTests(TestCase): res = self.client.get('/dates/books/2007/week/no_week/') 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): fixtures = ['generic-views-test-data.json'] urls = 'regressiontests.generic_views.urls' @@ -349,4 +359,3 @@ class DateDetailViewTests(TestCase): def test_invalid_url(self): self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/") - diff --git a/tests/regressiontests/generic_views/tests.py b/tests/regressiontests/generic_views/tests.py index 40eec72b251..843cabad151 100644 --- a/tests/regressiontests/generic_views/tests.py +++ b/tests/regressiontests/generic_views/tests.py @@ -2,4 +2,4 @@ from regressiontests.generic_views.base import ViewTest, TemplateViewTest, Redir from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests from regressiontests.generic_views.detail import DetailViewTest from regressiontests.generic_views.edit import CreateViewTests, UpdateViewTests, DeleteViewTests -from regressiontests.generic_views.list import ListViewTests \ No newline at end of file +from regressiontests.generic_views.list import ListViewTests diff --git a/tests/regressiontests/generic_views/urls.py b/tests/regressiontests/generic_views/urls.py index 548d10d1641..61f03873310 100644 --- a/tests/regressiontests/generic_views/urls.py +++ b/tests/regressiontests/generic_views/urls.py @@ -149,6 +149,8 @@ urlpatterns = patterns('', views.BookWeekArchive.as_view(allow_future=True)), (r'^dates/books/(?P\d{4})/week/no_week/$', views.BookWeekArchive.as_view()), + (r'^dates/books/(?P\d{4})/week/(?P\d{1,2})/monday/$', + views.BookWeekArchive.as_view(week_format='%W')), # DayArchiveView (r'^dates/books/(?P\d{4})/(?P[a-z]{3})/(?P\d{1,2})/$',