Ticket #1282: 1282.diff
File 1282.diff, 4.0 KB (added by , 16 years ago) |
---|
-
django/views/generic/date_based.py
274 274 c[key] = value 275 275 return HttpResponse(t.render(c), mimetype=mimetype) 276 276 277 def archive_today(request, **kwargs):277 def archive_today(request, month_format='%b', **kwargs): 278 278 """ 279 279 Generic daily archive view for today. Same as archive_day view. 280 280 """ 281 281 today = datetime.date.today() 282 282 kwargs.update({ 283 283 'year': str(today.year), 284 'month': today.strftime( '%b').lower(),284 'month': today.strftime(month_format).lower(), 285 285 'day': str(today.day), 286 286 }) 287 return archive_day(request, **kwargs)287 return archive_day(request, month_format=month_format, **kwargs) 288 288 289 289 def object_detail(request, year, month, day, queryset, date_field, 290 290 month_format='%b', day_format='%d', object_id=None, slug=None, -
tests/regressiontests/views/tests/generic/date_based.py
67 67 article.save() 68 68 response = self.client.get('/views/date_based/archive_month/2004/02/') 69 69 self.assertEqual(response.status_code, 404) 70 71 72 No newline at end of file 70 71 class DayArchiveTest(TestCase): 72 fixtures = ['testdata.json'] 73 74 def setUp(self): 75 # Correct the date for the current article 76 current_article = Article.objects.get(title="Current Article") 77 current_article.date_created = datetime.now() 78 current_article.save() 79 80 def test_archive_today(self): 81 response = self.client.get('/views/date_based/today/') 82 self.assertEqual(response.status_code, 200) 83 objects = response.context['object_list'] 84 self.assertEqual(len(objects), 1) 85 self.assertEqual(objects[0].title, 'Current Article') 86 87 def test_archive_today_month_format(self): 88 response = self.client.get('/views/date_based/today_month_format/') 89 self.assertEqual(response.status_code, 200) 90 objects = response.context['object_list'] 91 self.assertEqual(len(objects), 1) 92 self.assertEqual(objects[0].title, 'Current Article') 93 94 def test_archive_day_abbrev_month(self): 95 response = self.client.get('/views/date_based/archive_day/2001/jan/1/') 96 self.assertEqual(response.status_code, 200) 97 objects = response.context['object_list'] 98 self.assertEqual(len(objects), 1) 99 self.assertEqual(objects[0].title, 'Old Article') 100 101 def test_archive_day_numeric_month(self): 102 response = self.client.get('/views/date_based/archive_day/2001/1/1/') 103 self.assertEqual(response.status_code, 200) 104 objects = response.context['object_list'] 105 self.assertEqual(len(objects), 1) 106 self.assertEqual(objects[0].title, 'Old Article') -
tests/regressiontests/views/urls.py
48 48 (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 49 49 'archive_month', 50 50 date_based_info_dict), 51 (r'^date_based/today/$', 52 'archive_today', 53 date_based_info_dict), 54 (r'^date_based/today_month_format/$', 55 'archive_today', 56 dict(date_based_info_dict, month_format='%m')), 57 (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$', 58 'archive_day', 59 dict(date_based_info_dict, month_format='%b')), 60 (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', 61 'archive_day', 62 dict(date_based_info_dict, month_format='%m')), 51 63 ) 52 64 53 65 # crud generic views.