Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.0.X] Fixed #7944: date-based generic views no longer get confused …

…with a numeric month format. Thanks to Justin Lilly and Alex Gaynor. Backport of r10457 and r10458 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10459 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8c3d593b0f6d8c3a60eb6f95a687ec42a77340c4 1 parent 3891c13
@jacobian jacobian authored
View
1  AUTHORS
@@ -253,6 +253,7 @@ answer newbie questions, and generally made Django that much better:
Christopher Lenz <http://www.cmlenz.net/>
lerouxb@gmail.com
Piotr Lewandowski <piotr.lewandowski@gmail.com>
+ Justin Lilly <justinlilly@gmail.com>
Waylan Limberg <waylan@gmail.com>
limodou
Philip Lindborg <philip.lindborg@gmail.com>
View
14 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
View
11 tests/regressiontests/views/tests/generic/date_based.py
@@ -90,3 +90,14 @@ def test_archive_month_includes_only_month(self):
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)
View
5 tests/regressiontests/views/urls.py
@@ -20,6 +20,8 @@
'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 @@
(r'^date_based/object_detail/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/allow_future/$',
'object_detail',
dict(allow_future=True, slug_field='slug', **date_based_info_dict)),
+ (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
+ 'archive_day',
+ numeric_days_info_dict),
(r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
'archive_month',
date_based_info_dict),
View
1  tests/templates/views/article_archive_day.html
@@ -0,0 +1 @@
+This template intentionally left blank
Please sign in to comment.
Something went wrong with that request. Please try again.