Ticket #3274: month_archive_date_list.diff
File month_archive_date_list.diff, 3.2 KB (added by , 15 years ago) |
---|
-
django/views/generic/date_based.py
105 105 106 106 Templates: ``<app_label>/<model_name>_archive_month.html`` 107 107 Context: 108 date_list: 109 List of days in this month with objects 108 110 month: 109 111 (date) this month 110 112 next_month: … … 139 141 if last_day >= now.date() and not allow_future: 140 142 lookup_kwargs['%s__lte' % date_field] = now 141 143 object_list = queryset.filter(**lookup_kwargs) 144 date_list = object_list.dates(date_field, 'day') 142 145 if not object_list and not allow_empty: 143 146 raise Http404 144 147 … … 160 163 template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower()) 161 164 t = template_loader.get_template(template_name) 162 165 c = RequestContext(request, { 166 'date_list': date_list, 163 167 '%s_list' % template_object_name: object_list, 164 168 'month': date, 165 169 'next_month': next_month, -
tests/regressiontests/views/tests/generic/date_based.py
110 110 self.assertEqual(response.status_code, 200) 111 111 self.assertEqual(response.context['next_month'], None) 112 112 self.assertEqual(response.context['previous_month'], prev_month) 113 114 def test_archive_month_date_list(self): 115 author = Author(name="John Smith") 116 author.save() 117 date1 = datetime(2010, 1, 1, 0, 0, 0) 118 date2 = datetime(2010, 1, 2, 0, 0, 0) 119 Article.objects.create(title='example1', author=author, date_created=date1) 120 Article.objects.create(title='example2', author=author, date_created=date2) 121 response = self.client.get('/views/date_based/archive_month/2010/1/') 122 self.assertEqual(response.status_code, 200) 123 self.assertEqual(len(response.context['date_list']), 2) 124 self.assertEqual(response.context['date_list'][0], date1) 125 # Checks that the same date is not included more than once in the list 126 Article.objects.create(title='example2', author=author, date_created=date2) 127 response = self.client.get('/views/date_based/archive_month/2010/1/') 128 self.assertEqual(len(response.context['date_list']), 2) 113 129 114 130 class DayArchiveTests(TestCase): 115 131 -
docs/ref/generic-views.txt
371 371 372 372 In addition to ``extra_context``, the template's context will be: 373 373 374 .. versionadded:: 1.2 375 376 * ``date_list``: A list of ``datetime.date`` objects representing all 377 days that have objects available in the given month, according to 378 ``queryset``, in ascending order. 379 374 380 * ``month``: A ``datetime.date`` object representing the given month. 375 381 376 382 * ``next_month``: A ``datetime.date`` object representing the first day of