1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Paginator._get_page hook

This allows for Paginator subclasses to easily override the Page class
that gets used.

Took the opportunity to also do some non-invasive PEP8 tidying of the
paginator module.
This commit is contained in:
Chris Beaven
2012-11-21 14:58:14 +13:00
parent 8fdb28219d
commit fbfa654a15
3 changed files with 67 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ from django.utils import six
from django.utils import unittest
from .models import Article
from .custom import ValidAdjacentNumsPaginator
class PaginationTests(unittest.TestCase):
@@ -217,6 +218,20 @@ class PaginationTests(unittest.TestCase):
self.assertEqual(''.join(page2), 'fghijk')
self.assertEqual(''.join(reversed(page2)), 'kjihgf')
def test_get_page_hook(self):
"""
Tests that a Paginator subclass can use the ``_get_page`` hook to
return an alternative to the standard Page class.
"""
eleven = 'abcdefghijk'
paginator = ValidAdjacentNumsPaginator(eleven, per_page=6)
page1 = paginator.page(1)
page2 = paginator.page(2)
self.assertEquals(page1.previous_page_number(), None)
self.assertEquals(page1.next_page_number(), 2)
self.assertEquals(page2.previous_page_number(), 1)
self.assertEquals(page2.next_page_number(), None)
class ModelPaginationTests(TestCase):
"""