Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15653 - Error in admin pagination tag.

Thanks jcumbo@ for the report and adamzap
and nott for the patch.
  • Loading branch information...
commit 5939864616d56cf949f0bca348a8e05230b62fe0 1 parent 7426e72
Tim Graham authored
2  django/contrib/admin/templatetags/admin_list.py
@@ -62,7 +62,7 @@ def pagination(cl):
62 62
             # ON_EACH_SIDE links at either end of the "current page" link.
63 63
             page_range = []
64 64
             if page_num > (ON_EACH_SIDE + ON_ENDS):
65  
-                page_range.extend(range(0, ON_EACH_SIDE - 1))
  65
+                page_range.extend(range(0, ON_ENDS))
66 66
                 page_range.append(DOT)
67 67
                 page_range.extend(range(page_num - ON_EACH_SIDE, page_num + 1))
68 68
             else:
39  tests/admin_changelist/tests.py
@@ -4,6 +4,7 @@
4 4
 
5 5
 from django.contrib import admin
6 6
 from django.contrib.admin.options import IncorrectLookupParameters
  7
+from django.contrib.admin.templatetags.admin_list import pagination
7 8
 from django.contrib.admin.views.main import ChangeList, SEARCH_VAR, ALL_VAR
8 9
 from django.contrib.auth.models import User
9 10
 from django.core.urlresolvers import reverse
@@ -564,6 +565,44 @@ def test_dynamic_list_filter(self):
564 565
         response = m.changelist_view(request)
565 566
         self.assertEqual(response.context_data['cl'].list_filter, ('parent', 'name', 'age'))
566 567
 
  568
+    def test_pagination_page_range(self):
  569
+        """
  570
+        Regression tests for ticket #15653: ensure the number of pages
  571
+        generated for changelist views are correct.
  572
+        """
  573
+        # instantiating and setting up ChangeList object
  574
+        m = GroupAdmin(Group, admin.site)
  575
+        request = self.factory.get('/group/')
  576
+        cl = ChangeList(request, Group, m.list_display,
  577
+                m.list_display_links, m.list_filter, m.date_hierarchy,
  578
+                m.search_fields, m.list_select_related, m.list_per_page,
  579
+                m.list_max_show_all, m.list_editable, m)
  580
+        per_page = cl.list_per_page = 10
  581
+
  582
+        for page_num, objects_count, expected_page_range in [
  583
+            (0, per_page, []),
  584
+            (0, per_page * 2, range(2)),
  585
+            (5, per_page * 11, list(range(11))),
  586
+            (5, per_page * 12, [0, 1, 2, 3, 4, 5, 6, 7, 8, '.', 10, 11]),
  587
+            (6, per_page * 12, [0, 1, '.', 3, 4, 5, 6, 7, 8, 9, 10, 11]),
  588
+            (6, per_page * 13, [0, 1, '.', 3, 4, 5, 6, 7, 8, 9, '.', 11, 12]),
  589
+        ]:
  590
+            # assuming we have exactly `objects_count` objects
  591
+            Group.objects.all().delete()
  592
+            for i in range(objects_count):
  593
+                Group.objects.create(name='test band')
  594
+
  595
+            # setting page number and calculating page range
  596
+            cl.page_num = page_num
  597
+            cl.get_results(request)
  598
+            real_page_range = pagination(cl)['page_range']
  599
+
  600
+            self.assertEqual(
  601
+                expected_page_range,
  602
+                real_page_range,
  603
+            )
  604
+
  605
+
567 606
 class AdminLogNodeTestCase(TestCase):
568 607
 
569 608
     def test_get_admin_log_templatetag_custom_user(self):

0 notes on commit 5939864

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