Ticket #1282: ticket1282-rev13294.diff
File ticket1282-rev13294.diff, 4.0 KB (added by , 15 years ago) |
---|
-
django/views/generic/date_based.py
294 294 c[key] = value 295 295 return HttpResponse(t.render(c), mimetype=mimetype) 296 296 297 def archive_today(request, **kwargs):297 def archive_today(request, month_format='%b', **kwargs): 298 298 """ 299 299 Generic daily archive view for today. Same as archive_day view. 300 300 """ 301 301 today = datetime.date.today() 302 302 kwargs.update({ 303 303 'year': str(today.year), 304 'month': today.strftime( '%b').lower(),304 'month': today.strftime(month_format).lower(), 305 305 'day': str(today.day), 306 306 }) 307 return archive_day(request, **kwargs)307 return archive_day(request, month_format=month_format, **kwargs) 308 308 309 309 def object_detail(request, year, month, day, queryset, date_field, 310 310 month_format='%b', day_format='%d', object_id=None, slug=None, -
tests/regressiontests/views/tests/generic/date_based.py
128 128 self.assertEqual(len(response.context['date_list']), 2) 129 129 130 130 class DayArchiveTests(TestCase): 131 131 fixtures = ['testdata.json'] 132 133 def setUp(self): 134 # Correct the date for the current article 135 current_article = Article.objects.get(title="Current Article") 136 current_article.date_created = datetime.now() 137 current_article.save() 138 139 def test_archive_today(self): 140 response = self.client.get('/views/date_based/today/') 141 self.assertEqual(response.status_code, 200) 142 objects = response.context['object_list'] 143 self.assertEqual(len(objects), 1) 144 self.assertEqual(objects[0].title, 'Current Article') 145 146 def test_archive_today_month_format(self): 147 response = self.client.get('/views/date_based/today_month_format/') 148 self.assertEqual(response.status_code, 200) 149 objects = response.context['object_list'] 150 self.assertEqual(len(objects), 1) 151 self.assertEqual(objects[0].title, 'Current Article') 152 153 def test_archive_day_abbrev_month(self): 154 response = self.client.get('/views/date_based/archive_day/2001/jan/1/') 155 self.assertEqual(response.status_code, 200) 156 objects = response.context['object_list'] 157 self.assertEqual(len(objects), 1) 158 self.assertEqual(objects[0].title, 'Old Article') 159 160 def test_archive_day_numeric_month(self): 161 response = self.client.get('/views/date_based/archive_day/2001/1/1/') 162 self.assertEqual(response.status_code, 200) 163 objects = response.context['object_list'] 164 self.assertEqual(len(objects), 1) 165 self.assertEqual(objects[0].title, 'Old Article') 166 132 167 def test_year_month_day_format(self): 133 168 """ 134 169 Make sure day views don't get confused with numeric month formats (#7944) -
tests/regressiontests/views/urls.py
74 74 (r'^date_based/datefield/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 75 75 'archive_month', 76 76 date_based_datefield_info_dict), 77 (r'^date_based/today/$', 78 'archive_today', 79 date_based_info_dict), 80 (r'^date_based/today_month_format/$', 81 'archive_today', 82 dict(date_based_info_dict, month_format='%m')), 83 (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$', 84 'archive_day', 85 dict(date_based_info_dict, month_format='%b')), 86 (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', 87 'archive_day', 88 dict(date_based_info_dict, month_format='%m')), 77 89 ) 78 90 79 91 # crud generic views.