Author: jacob
Date: 2009-04-09 10:23:56 -0500 (Thu, 09 Apr 2009)
New Revision: 10457

Modified:
   django/trunk/AUTHORS
   django/trunk/django/views/generic/date_based.py
   django/trunk/tests/regressiontests/views/tests/generic/date_based.py
   django/trunk/tests/regressiontests/views/urls.py
Log:
Fixed #7944: date-based generic views no longer get confused with a numeric 
month format. Thanks to Justin Lilly and Alex Gaynor.

Modified: django/trunk/AUTHORS
===================================================================
--- django/trunk/AUTHORS        2009-04-09 15:09:35 UTC (rev 10456)
+++ django/trunk/AUTHORS        2009-04-09 15:23:56 UTC (rev 10457)
@@ -263,6 +263,7 @@
     Christopher Lenz <http://www.cmlenz.net/>
     lero...@gmail.com
     Piotr Lewandowski <piotr.lewandow...@gmail.com>
+    Justin Lilly <justinli...@gmail.com>
     Waylan Limberg <way...@gmail.com>
     limodou
     Philip Lindborg <philip.lindb...@gmail.com>

Modified: django/trunk/django/views/generic/date_based.py
===================================================================
--- django/trunk/django/views/generic/date_based.py     2009-04-09 15:09:35 UTC 
(rev 10456)
+++ django/trunk/django/views/generic/date_based.py     2009-04-09 15:23:56 UTC 
(rev 10457)
@@ -116,7 +116,8 @@
     """
     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 @@
     """
     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 @@
     """
     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 @@
     """
     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
 

Modified: django/trunk/tests/regressiontests/views/tests/generic/date_based.py
===================================================================
--- django/trunk/tests/regressiontests/views/tests/generic/date_based.py        
2009-04-09 15:09:35 UTC (rev 10456)
+++ django/trunk/tests/regressiontests/views/tests/generic/date_based.py        
2009-04-09 15:23:56 UTC (rev 10457)
@@ -90,3 +90,14 @@
         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

Modified: django/trunk/tests/regressiontests/views/urls.py
===================================================================
--- django/trunk/tests/regressiontests/views/urls.py    2009-04-09 15:09:35 UTC 
(rev 10456)
+++ django/trunk/tests/regressiontests/views/urls.py    2009-04-09 15:23:56 UTC 
(rev 10457)
@@ -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),


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to