Ticket #1282: patch-1282.diff
File patch-1282.diff, 4.1 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 'month_format': month_format, 286 287 }) 287 288 return archive_day(request, **kwargs) 288 289 -
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
21 21 'month_format': '%m', 22 22 } 23 23 24 # For testing of archive_day 25 archive_day_info_dict = { 26 'queryset': Article.objects.all(), 27 'date_field': 'date_created', 28 } 29 24 30 urlpatterns = patterns('', 25 31 (r'^$', views.index_page), 26 32 … … 48 54 (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 49 55 'archive_month', 50 56 date_based_info_dict), 57 (r'^date_based/today/$', 58 'archive_today', 59 archive_day_info_dict), 60 (r'^date_based/today_month_format/$', 61 'archive_today', 62 dict(archive_day_info_dict, month_format='%m')), 63 (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$', 64 'archive_day', 65 dict(archive_day_info_dict, month_format='%b')), 66 (r'^date_based/archive_day/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', 67 'archive_day', 68 dict(archive_day_info_dict, month_format='%m')), 51 69 ) 52 70 53 71 # crud generic views.