Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14864 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ff8711a825ea9bbe98e873d7aa28ce5135528fec 1 parent b37d867
Chris Beaven authored December 09, 2010
6  django/views/generic/list.py
@@ -32,9 +32,9 @@ def paginate_queryset(self, queryset, page_size):
32 32
         """
33 33
         Paginate the queryset, if needed.
34 34
         """
35  
-        if queryset.count() > page_size:
36  
-            paginator = self.get_paginator(queryset, page_size, allow_empty_first_page=self.get_allow_empty())
37  
-            page = self.kwargs.get('page', None) or self.request.GET.get('page', 1)
  35
+        paginator = self.get_paginator(queryset, page_size, allow_empty_first_page=self.get_allow_empty())
  36
+        if paginator.num_pages > 1:
  37
+            page = self.kwargs.get('page') or self.request.GET.get('page') or 1
38 38
             try:
39 39
                 page_number = int(page)
40 40
             except ValueError:
10  docs/ref/class-based-views.txt
@@ -344,22 +344,22 @@ MultipleObjectMixin
344 344
 
345 345
     **Context**
346 346
 
347  
-        * ``object_list``: The list of object that this view is displaying. If
  347
+        * ``object_list``: The list of objects that this view is displaying. If
348 348
           ``context_object_name`` is specified, that variable will also be set
349 349
           in the context, with the same value as ``object_list``.
350 350
 
351 351
         * ``is_paginated``: A boolean representing whether the results are
352 352
           paginated. Specifically, this is set to ``False`` if no page size has
353  
-          been specified, or if the number of available objects is less than or
354  
-          equal to ``paginate_by``.
  353
+          been specified, or if the available objects do not span multiple
  354
+          pages.
355 355
 
356 356
         * ``paginator``: An instance of
357 357
           :class:`django.core.paginator.Paginator`. If the page is not
358  
-          paginated, this context variable will be ``None``
  358
+          paginated, this context variable will be ``None``.
359 359
 
360 360
         * ``page_obj``: An instance of
361 361
           :class:`django.core.paginator.Page`. If the page is not paginated,
362  
-          this context variable will be ``None``
  362
+          this context variable will be ``None``.
363 363
 
364 364
 MultipleObjectTemplateResponseMixin
365 365
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7  tests/regressiontests/generic_views/list.py
@@ -90,7 +90,7 @@ def test_paginated_custom_paginator_class(self):
90 90
         self._make_authors(7)
91 91
         res = self.client.get('/list/authors/paginated/custom_class/')
92 92
         self.assertEqual(res.status_code, 200)
93  
-        self.assertIsInstance(res.context['paginator'], CustomPaginator)
  93
+        self.assertIsNone(res.context['paginator'])
94 94
         # Custom pagination allows for 2 orphans on a page size of 5
95 95
         self.assertEqual(len(res.context['object_list']), 7)
96 96
 
@@ -101,6 +101,11 @@ def test_paginated_custom_paginator_constructor(self):
101 101
         # Custom pagination allows for 2 orphans on a page size of 5
102 102
         self.assertEqual(len(res.context['object_list']), 7)
103 103
 
  104
+    def test_paginated_non_queryset(self):
  105
+        res = self.client.get('/list/dict/paginated/')
  106
+        self.assertEqual(res.status_code, 200)
  107
+        self.assertEqual(len(res.context['object_list']), 1)
  108
+
104 109
     def test_allow_empty_false(self):
105 110
         res = self.client.get('/list/authors/notempty/')
106 111
         self.assertEqual(res.status_code, 200)
2  tests/regressiontests/generic_views/urls.py
@@ -98,6 +98,8 @@
98 98
     # ListView
99 99
     (r'^list/dict/$',
100 100
         views.DictList.as_view()),
  101
+    (r'^list/dict/paginated/$',
  102
+        views.DictList.as_view(paginate_by=1)),
101 103
     url(r'^list/authors/$',
102 104
         views.AuthorList.as_view(),
103 105
         name="authors_list"),

0 notes on commit ff8711a

Please sign in to comment.
Something went wrong with that request. Please try again.