diff --git a/AUTHORS b/AUTHORS
index a2924e9310..be716abe43 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -263,6 +263,7 @@ answer newbie questions, and generally made Django that much better:
Christopher Lenz
lerouxb@gmail.com
Piotr Lewandowski
+ Justin Lilly
Waylan Limberg
limodou
Philip Lindborg
diff --git a/django/views/generic/date_based.py b/django/views/generic/date_based.py
index c5f1748a89..5807e79573 100644
--- a/django/views/generic/date_based.py
+++ b/django/views/generic/date_based.py
@@ -116,7 +116,8 @@ def archive_month(request, year, month, queryset, date_field,
"""
if extra_context is None: extra_context = {}
try:
- date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3])
+ tt = time.strptime("%s-%s" % (year, month), '%s-%s' % ('%Y', month_format))
+ date = datetime.date(*tt[:3])
except ValueError:
raise Http404
@@ -181,7 +182,8 @@ def archive_week(request, year, week, queryset, date_field,
"""
if extra_context is None: extra_context = {}
try:
- date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%U')[:3])
+ tt = time.strptime(year+'-0-'+week, '%Y-%w-%U')
+ date = datetime.date(*tt[:3])
except ValueError:
raise Http404
@@ -237,7 +239,9 @@ def archive_day(request, year, month, day, queryset, date_field,
"""
if extra_context is None: extra_context = {}
try:
- date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
+ tt = time.strptime('%s-%s-%s' % (year, month, day),
+ '%s-%s-%s' % ('%Y', month_format, day_format))
+ date = datetime.date(*tt[:3])
except ValueError:
raise Http404
@@ -307,7 +311,9 @@ def object_detail(request, year, month, day, queryset, date_field,
"""
if extra_context is None: extra_context = {}
try:
- date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
+ tt = time.strptime('%s-%s-%s' % (year, month, day),
+ '%s-%s-%s' % ('%Y', month_format, day_format))
+ date = datetime.date(*tt[:3])
except ValueError:
raise Http404
diff --git a/tests/regressiontests/views/tests/generic/date_based.py b/tests/regressiontests/views/tests/generic/date_based.py
index 3cb7e1e10f..1ec55c89f4 100644
--- a/tests/regressiontests/views/tests/generic/date_based.py
+++ b/tests/regressiontests/views/tests/generic/date_based.py
@@ -90,3 +90,14 @@ class MonthArchiveTest(TestCase):
response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
self.assertEqual(response.status_code, 404)
+class DayArchiveTests(TestCase):
+
+ def test_year_month_day_format(self):
+ """
+ Make sure day views don't get confused with numeric month formats (#7944)
+ """
+ author = Author.objects.create(name="John Smith")
+ article = Article.objects.create(title="example", author=author, date_created=datetime(2004, 1, 21, 0, 0, 1))
+ response = self.client.get('/views/date_based/archive_day/2004/1/21/')
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['object_list'][0], article)
\ No newline at end of file
diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py
index b6a269f9f4..0879c7428e 100644
--- a/tests/regressiontests/views/urls.py
+++ b/tests/regressiontests/views/urls.py
@@ -20,6 +20,8 @@ date_based_info_dict = {
'date_field': 'date_created',
'month_format': '%m',
}
+numeric_days_info_dict = dict(date_based_info_dict, day_format='%d')
+
date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all())
urlpatterns = patterns('',
@@ -46,6 +48,9 @@ urlpatterns += patterns('django.views.generic.date_based',
(r'^date_based/object_detail/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P[-\w]+)/allow_future/$',
'object_detail',
dict(allow_future=True, slug_field='slug', **date_based_info_dict)),
+ (r'^date_based/archive_day/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/$',
+ 'archive_day',
+ numeric_days_info_dict),
(r'^date_based/archive_month/(?P\d{4})/(?P\d{1,2})/$',
'archive_month',
date_based_info_dict),