Author: SmileyChris
Date: 2010-12-08 20:34:14 -0600 (Wed, 08 Dec 2010)
New Revision: 14864
Modified:
django/trunk/django/views/generic/list.py
django/trunk/docs/ref/class-based-views.txt
django/trunk/tests/regressiontests/generic_views/list.py
django/trunk/tests/regressiontests/generic_views/urls.py
Log:
Fixes #14873 -- A paginated ListView with a List instead of queryset produces
an error.
Additional minor change in functionality: the page is now not considered
paginated if the objects do not span multiple pages according to the paginator.
This will only affect views with a custom paginator method which uses orphans.
Modified: django/trunk/django/views/generic/list.py
===================================================================
--- django/trunk/django/views/generic/list.py 2010-12-09 00:47:37 UTC (rev
14863)
+++ django/trunk/django/views/generic/list.py 2010-12-09 02:34:14 UTC (rev
14864)
@@ -32,9 +32,9 @@
"""
Paginate the queryset, if needed.
"""
- if queryset.count() > page_size:
- paginator = self.get_paginator(queryset, page_size,
allow_empty_first_page=self.get_allow_empty())
- page = self.kwargs.get('page', None) or
self.request.GET.get('page', 1)
+ paginator = self.get_paginator(queryset, page_size,
allow_empty_first_page=self.get_allow_empty())
+ if paginator.num_pages > 1:
+ page = self.kwargs.get('page') or self.request.GET.get('page') or 1
try:
page_number = int(page)
except ValueError:
Modified: django/trunk/docs/ref/class-based-views.txt
===================================================================
--- django/trunk/docs/ref/class-based-views.txt 2010-12-09 00:47:37 UTC (rev
14863)
+++ django/trunk/docs/ref/class-based-views.txt 2010-12-09 02:34:14 UTC (rev
14864)
@@ -344,22 +344,22 @@
**Context**
- * ``object_list``: The list of object that this view is displaying. If
+ * ``object_list``: The list of objects that this view is displaying. If
``context_object_name`` is specified, that variable will also be set
in the context, with the same value as ``object_list``.
* ``is_paginated``: A boolean representing whether the results are
paginated. Specifically, this is set to ``False`` if no page size has
- been specified, or if the number of available objects is less than or
- equal to ``paginate_by``.
+ been specified, or if the available objects do not span multiple
+ pages.
* ``paginator``: An instance of
:class:`django.core.paginator.Paginator`. If the page is not
- paginated, this context variable will be ``None``
+ paginated, this context variable will be ``None``.
* ``page_obj``: An instance of
:class:`django.core.paginator.Page`. If the page is not paginated,
- this context variable will be ``None``
+ this context variable will be ``None``.
MultipleObjectTemplateResponseMixin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Modified: django/trunk/tests/regressiontests/generic_views/list.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/list.py 2010-12-09
00:47:37 UTC (rev 14863)
+++ django/trunk/tests/regressiontests/generic_views/list.py 2010-12-09
02:34:14 UTC (rev 14864)
@@ -90,7 +90,7 @@
self._make_authors(7)
res = self.client.get('/list/authors/paginated/custom_class/')
self.assertEqual(res.status_code, 200)
- self.assertIsInstance(res.context['paginator'], CustomPaginator)
+ self.assertIsNone(res.context['paginator'])
# Custom pagination allows for 2 orphans on a page size of 5
self.assertEqual(len(res.context['object_list']), 7)
@@ -101,6 +101,11 @@
# Custom pagination allows for 2 orphans on a page size of 5
self.assertEqual(len(res.context['object_list']), 7)
+ def test_paginated_non_queryset(self):
+ res = self.client.get('/list/dict/paginated/')
+ self.assertEqual(res.status_code, 200)
+ self.assertEqual(len(res.context['object_list']), 1)
+
def test_allow_empty_false(self):
res = self.client.get('/list/authors/notempty/')
self.assertEqual(res.status_code, 200)
Modified: django/trunk/tests/regressiontests/generic_views/urls.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/urls.py 2010-12-09
00:47:37 UTC (rev 14863)
+++ django/trunk/tests/regressiontests/generic_views/urls.py 2010-12-09
02:34:14 UTC (rev 14864)
@@ -98,6 +98,8 @@
# ListView
(r'^list/dict/$',
views.DictList.as_view()),
+ (r'^list/dict/paginated/$',
+ views.DictList.as_view(paginate_by=1)),
url(r'^list/authors/$',
views.AuthorList.as_view(),
name="authors_list"),
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.