diff --git a/django/views/generic/list.py b/django/views/generic/list.py
index 5668457..5135763 100644
a
|
b
|
class MultipleObjectMixin(object):
|
89 | 89 | """ |
90 | 90 | queryset = kwargs.pop('object_list') |
91 | 91 | page_size = self.get_paginate_by(queryset) |
| 92 | context_object_name = self.get_context_object_name(queryset) |
92 | 93 | if page_size: |
93 | 94 | paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size) |
94 | 95 | context = { |
… |
… |
class MultipleObjectMixin(object):
|
105 | 106 | 'object_list': queryset |
106 | 107 | } |
107 | 108 | context.update(kwargs) |
108 | | context_object_name = self.get_context_object_name(queryset) |
109 | 109 | if context_object_name is not None: |
110 | 110 | context[context_object_name] = queryset |
111 | 111 | return context |
diff --git a/tests/regressiontests/generic_views/dates.py b/tests/regressiontests/generic_views/dates.py
index d5345be..14eba72 100644
a
|
b
|
class YearArchiveViewTests(TestCase):
|
118 | 118 | res = self.client.get('/dates/books/%s/allow_future/' % year) |
119 | 119 | self.assertEqual(res.status_code, 200) |
120 | 120 | self.assertEqual(list(res.context['date_list']), [datetime.datetime(year, 1, 1)]) |
121 | | |
| 121 | |
| 122 | def test_year_view_paginated(self): |
| 123 | res = self.client.get('/dates/books/2006/paginated/') |
| 124 | self.assertEqual(res.status_code, 200) |
| 125 | self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2006))) |
| 126 | self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2006))) |
| 127 | self.assertTemplateUsed(res, 'generic_views/book_archive_year.html') |
| 128 | |
122 | 129 | def test_year_view_invalid_pattern(self): |
123 | 130 | res = self.client.get('/dates/books/no_year/') |
124 | 131 | self.assertEqual(res.status_code, 404) |
… |
… |
class MonthArchiveViewTests(TestCase):
|
189 | 196 | self.assertEqual(res.status_code, 200) |
190 | 197 | self.assertEqual(res.context['next_month'], future) |
191 | 198 | self.assertEqual(res.context['previous_month'], datetime.date(2006, 5, 1)) |
192 | | |
| 199 | |
| 200 | def test_month_view_paginated(self): |
| 201 | res = self.client.get('/dates/books/2008/oct/paginated/') |
| 202 | self.assertEqual(res.status_code, 200) |
| 203 | self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10))) |
| 204 | self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10))) |
| 205 | self.assertTemplateUsed(res, 'generic_views/book_archive_month.html') |
| 206 | |
193 | 207 | def test_custom_month_format(self): |
194 | 208 | res = self.client.get('/dates/books/2008/10/') |
195 | 209 | self.assertEqual(res.status_code, 200) |
… |
… |
class WeekArchiveViewTests(TestCase):
|
250 | 264 | res = self.client.get('/dates/books/%s/week/1/allow_future/' % future.year) |
251 | 265 | self.assertEqual(res.status_code, 200) |
252 | 266 | self.assertEqual(list(res.context['book_list']), [b]) |
253 | | |
| 267 | |
| 268 | def test_week_view_paginated(self): |
| 269 | week_start = datetime.date(2008, 9, 28) |
| 270 | week_end = week_start + datetime.timedelta(days=7) |
| 271 | res = self.client.get('/dates/books/2008/week/39/') |
| 272 | self.assertEqual(res.status_code, 200) |
| 273 | self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__gte=week_start, pubdate__lt=week_end))) |
| 274 | self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__gte=week_start, pubdate__lt=week_end))) |
| 275 | self.assertTemplateUsed(res, 'generic_views/book_archive_week.html') |
| 276 | |
254 | 277 | def test_week_view_invalid_pattern(self): |
255 | 278 | res = self.client.get('/dates/books/2007/week/no_week/') |
256 | 279 | self.assertEqual(res.status_code, 404) |
… |
… |
class DayArchiveViewTests(TestCase):
|
326 | 349 | self.assertEqual(res.status_code, 200) |
327 | 350 | self.assertEqual(res.context['next_day'], future) |
328 | 351 | self.assertEqual(res.context['previous_day'], datetime.date(2006, 5, 1)) |
329 | | |
| 352 | |
| 353 | def test_day_view_paginated(self): |
| 354 | res = self.client.get('/dates/books/2008/oct/1/') |
| 355 | self.assertEqual(res.status_code, 200) |
| 356 | self.assertEqual(list(res.context['book_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10, pubdate__day=1))) |
| 357 | self.assertEqual(list(res.context['object_list']), list(Book.objects.filter(pubdate__year=2008, pubdate__month=10, pubdate__day=1))) |
| 358 | self.assertTemplateUsed(res, 'generic_views/book_archive_day.html') |
| 359 | |
330 | 360 | def test_next_prev_context(self): |
331 | 361 | res = self.client.get('/dates/books/2008/oct/01/') |
332 | 362 | self.assertEqual(res.content, "Archive for Oct. 1, 2008. Previous day is May 1, 2006") |
diff --git a/tests/regressiontests/generic_views/urls.py b/tests/regressiontests/generic_views/urls.py
index c06b5d8..067c1f6 100644
a
|
b
|
urlpatterns = patterns('',
|
146 | 146 | views.BookYearArchive.as_view(allow_empty=True)), |
147 | 147 | (r'^dates/books/(?P<year>\d{4})/allow_future/$', |
148 | 148 | views.BookYearArchive.as_view(allow_future=True)), |
| 149 | (r'^dates/books/(?P<year>\d{4})/paginated/$', |
| 150 | views.BookYearArchive.as_view(make_object_list=True, paginate_by=30)), |
149 | 151 | (r'^dates/books/no_year/$', |
150 | 152 | views.BookYearArchive.as_view()), |
151 | 153 | |
… |
… |
urlpatterns = patterns('',
|
158 | 160 | views.BookMonthArchive.as_view(allow_empty=True)), |
159 | 161 | (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/allow_future/$', |
160 | 162 | views.BookMonthArchive.as_view(allow_future=True)), |
| 163 | (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/paginated/$', |
| 164 | views.BookMonthArchive.as_view(paginate_by=30)), |
161 | 165 | (r'^dates/books/(?P<year>\d{4})/no_month/$', |
162 | 166 | views.BookMonthArchive.as_view()), |
163 | 167 | |
… |
… |
urlpatterns = patterns('',
|
168 | 172 | views.BookWeekArchive.as_view(allow_empty=True)), |
169 | 173 | (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/allow_future/$', |
170 | 174 | views.BookWeekArchive.as_view(allow_future=True)), |
| 175 | (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/paginated/$', |
| 176 | views.BookWeekArchive.as_view(paginate_by=30)), |
171 | 177 | (r'^dates/books/(?P<year>\d{4})/week/no_week/$', |
172 | 178 | views.BookWeekArchive.as_view()), |
173 | 179 | (r'^dates/books/(?P<year>\d{4})/week/(?P<week>\d{1,2})/monday/$', |
… |
… |
urlpatterns = patterns('',
|
182 | 188 | views.BookDayArchive.as_view(allow_empty=True)), |
183 | 189 | (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/allow_future/$', |
184 | 190 | views.BookDayArchive.as_view(allow_future=True)), |
| 191 | (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/paginated/$', |
| 192 | views.BookDayArchive.as_view(paginate_by=True)), |
185 | 193 | (r'^dates/books/(?P<year>\d{4})/(?P<month>[a-z]{3})/no_day/$', |
186 | 194 | views.BookDayArchive.as_view()), |
187 | 195 | |