Code

Ticket #1282: 1282.diff

File 1282.diff, 4.0 KB (added by SmileyChris, 6 years ago)
Line 
1Index: django/views/generic/date_based.py
2===================================================================
3--- django/views/generic/date_based.py  (revision 8066)
4+++ django/views/generic/date_based.py  (working copy)
5@@ -274,17 +274,17 @@
6             c[key] = value
7     return HttpResponse(t.render(c), mimetype=mimetype)
8 
9-def archive_today(request, **kwargs):
10+def archive_today(request, month_format='%b', **kwargs):
11     """
12     Generic daily archive view for today. Same as archive_day view.
13     """
14     today = datetime.date.today()
15     kwargs.update({
16         'year': str(today.year),
17-        'month': today.strftime('%b').lower(),
18+        'month': today.strftime(month_format).lower(),
19         'day': str(today.day),
20     })
21-    return archive_day(request, **kwargs)
22+    return archive_day(request, month_format=month_format, **kwargs)
23 
24 def object_detail(request, year, month, day, queryset, date_field,
25         month_format='%b', day_format='%d', object_id=None, slug=None,
26Index: tests/regressiontests/views/tests/generic/date_based.py
27===================================================================
28--- tests/regressiontests/views/tests/generic/date_based.py     (revision 8066)
29+++ tests/regressiontests/views/tests/generic/date_based.py     (working copy)
30@@ -67,5 +67,40 @@
31         article.save()
32         response = self.client.get('/views/date_based/archive_month/2004/02/')
33         self.assertEqual(response.status_code, 404)
34-               
35-       
36\ No newline at end of file
37+
38+class DayArchiveTest(TestCase):
39+    fixtures = ['testdata.json']
40+
41+    def setUp(self):
42+        # Correct the date for the current article
43+        current_article = Article.objects.get(title="Current Article")
44+        current_article.date_created = datetime.now()
45+        current_article.save()
46+
47+    def test_archive_today(self):
48+        response = self.client.get('/views/date_based/today/')
49+        self.assertEqual(response.status_code, 200)
50+        objects = response.context['object_list']
51+        self.assertEqual(len(objects), 1)
52+        self.assertEqual(objects[0].title, 'Current Article')
53+
54+    def test_archive_today_month_format(self):
55+        response = self.client.get('/views/date_based/today_month_format/')
56+        self.assertEqual(response.status_code, 200)
57+        objects = response.context['object_list']
58+        self.assertEqual(len(objects), 1)
59+        self.assertEqual(objects[0].title, 'Current Article')
60+
61+    def test_archive_day_abbrev_month(self):
62+        response = self.client.get('/views/date_based/archive_day/2001/jan/1/')
63+        self.assertEqual(response.status_code, 200)
64+        objects = response.context['object_list']
65+        self.assertEqual(len(objects), 1)
66+        self.assertEqual(objects[0].title, 'Old Article')
67+
68+    def test_archive_day_numeric_month(self):
69+        response = self.client.get('/views/date_based/archive_day/2001/1/1/')
70+        self.assertEqual(response.status_code, 200)
71+        objects = response.context['object_list']
72+        self.assertEqual(len(objects), 1)
73+        self.assertEqual(objects[0].title, 'Old Article')
74Index: tests/regressiontests/views/urls.py
75===================================================================
76--- tests/regressiontests/views/urls.py (revision 8066)
77+++ tests/regressiontests/views/urls.py (working copy)
78@@ -48,6 +48,18 @@
79     (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$',
80         'archive_month',
81         date_based_info_dict),
82+    (r'^date_based/today/$',
83+        'archive_today',
84+        date_based_info_dict),
85+    (r'^date_based/today_month_format/$',
86+        'archive_today',
87+        dict(date_based_info_dict, month_format='%m')),
88+    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$',
89+        'archive_day',
90+        dict(date_based_info_dict, month_format='%b')),
91+    (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$',
92+        'archive_day',
93+        dict(date_based_info_dict, month_format='%m')),
94 )
95 
96 # crud generic views.