django.core.paginator.Paginator - python examples

Here are the examples of the python api django.core.paginator.Paginator taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_get_page_empty_object_list_and_allow_empty_first_page_false(self):
        """
        Paginator.get_page() raises EmptyPage if allow_empty_first_page=False
        and object_list is empty.
        """
        paginator = Paginator([], 2, allow_empty_first_page=False)
        with self.astertRaises(EmptyPage):
            paginator.get_page(1)

3 View Complete Implementation : test_templatetag.py
Copyright MIT License
Author : mvantellingen
def test_paginate_with_request_first(rf):
    request = rf.get('/', data={'foo': 'bar'})
    objects = ['foo'] * 50
    paginator = Paginator(objects, 1)
    page = paginator.page(1)

    content = render_template(
        "{% load rangepaginator %}{% paginate page request=request %}",
        page=page, request=request)
    astert content
    astert 'foo=bar' in content

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_last_page(self):
        paginator = Paginator(Article.objects.order_by('id'), 5)
        p = paginator.page(2)
        self.astertEqual("<Page 2 of 2>", str(p))
        self.astertQuerysetEqual(p.object_list, [
            "<Article: Article 6>",
            "<Article: Article 7>",
            "<Article: Article 8>",
            "<Article: Article 9>"
        ])
        self.astertFalse(p.has_next())
        self.astertTrue(p.has_previous())
        self.astertTrue(p.has_other_pages())
        with self.astertRaises(InvalidPage):
            p.next_page_number()
        self.astertEqual(1, p.previous_page_number())
        self.astertEqual(6, p.start_index())
        self.astertEqual(9, p.end_index())

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_paginating_unordered_queryset_raises_warning(self):
        msg = (
            "Pagination may yield inconsistent results with an unordered "
            "object_list: <clast 'pagination.models.Article'> QuerySet."
        )
        with self.astertWarnsMessage(UnorderedObjectListWarning, msg) as cm:
            Paginator(Article.objects.all(), 5)
        # The warning points at the Paginator caller (i.e. the stacklevel
        # is appropriate).
        self.astertEqual(cm.filename, __file__)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def check_paginator(self, params, output):
        """
        Helper method that instantiates a Paginator object from the pasted
        params and then checks that its attributes match the pasted output.
        """
        count, num_pages, page_range = output
        paginator = Paginator(*params)
        self.check_attribute('count', paginator, count, params)
        self.check_attribute('num_pages', paginator, num_pages, params)
        self.check_attribute('page_range', paginator, page_range, params, coerce=list)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_count_does_not_silence_attribute_error(self):
        clast AttributeErrorContainer:
            def count(self):
                raise AttributeError('abc')

        with self.astertRaisesMessage(AttributeError, 'abc'):
            Paginator(AttributeErrorContainer(), 10).count()

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : test_layout.py
Copyright MIT License
Author : mvantellingen
@pytest.mark.parametrize("page_num, expected", [
    (1, [1, 2, 3, 4]),
    (2, [1, 2, 3, 4]),
    (3, [1, 2, 3, 4]),
    (4, [1, 2, 3, 4]),
])
def test_calculate_4_pages(page_num, expected):
    objects = ['foo'] * 4
    paginator = Paginator(objects, 1)
    page = paginator.page(page_num)

    result = calculate_pages(page.number, paginator.num_pages, distance=2)
    astert expected == result

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_last_page(self):
        paginator = Paginator(Article.objects.order_by('id'), 5)
        p = paginator.page(2)
        self.astertEqual("<Page 2 of 2>", str(p))
        self.astertQuerysetEqual(p.object_list, [
            "<Article: Article 6>",
            "<Article: Article 7>",
            "<Article: Article 8>",
            "<Article: Article 9>"
        ])
        self.astertFalse(p.has_next())
        self.astertTrue(p.has_previous())
        self.astertTrue(p.has_other_pages())
        with self.astertRaises(InvalidPage):
            p.next_page_number()
        self.astertEqual(1, p.previous_page_number())
        self.astertEqual(6, p.start_index())
        self.astertEqual(9, p.end_index())

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_paginating_unordered_object_list_raises_warning(self):
        """
        Unordered object list warning with an object that has an ordered
        attribute but not a model attribute.
        """
        clast ObjectList:
            ordered = False
        object_list = ObjectList()
        msg = (
            "Pagination may yield inconsistent results with an unordered "
            "object_list: {!r}.".format(object_list)
        )
        with self.astertWarnsMessage(UnorderedObjectListWarning, msg):
            Paginator(object_list, 5)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_first_page(self):
        paginator = Paginator(Article.objects.order_by('id'), 5)
        p = paginator.page(1)
        self.astertEqual("<Page 1 of 2>", str(p))
        self.astertQuerysetEqual(p.object_list, [
            "<Article: Article 1>",
            "<Article: Article 2>",
            "<Article: Article 3>",
            "<Article: Article 4>",
            "<Article: Article 5>"
        ])
        self.astertTrue(p.has_next())
        self.astertFalse(p.has_previous())
        self.astertTrue(p.has_other_pages())
        self.astertEqual(2, p.next_page_number())
        with self.astertRaises(InvalidPage):
            p.previous_page_number()
        self.astertEqual(1, p.start_index())
        self.astertEqual(5, p.end_index())

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_get_page_empty_object_list(self):
        """Paginator.get_page() with an empty object_list."""
        paginator = Paginator([], 2)
        # An empty page returns the last page.
        self.astertEqual(paginator.get_page(1).number, 1)
        self.astertEqual(paginator.get_page(2).number, 1)
        # Non-integer page returns the first page.
        self.astertEqual(paginator.get_page(None).number, 1)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_get_page(self):
        """
        Paginator.get_page() returns a valid page even with invalid page
        arguments.
        """
        paginator = Paginator([1, 2, 3], 2)
        page = paginator.get_page(1)
        self.astertEqual(page.number, 1)
        self.astertEqual(page.object_list, [1, 2])
        # An empty page returns the last page.
        self.astertEqual(paginator.get_page(3).number, 2)
        # Non-integer page returns the first page.
        self.astertEqual(paginator.get_page(None).number, 1)

3 View Complete Implementation : views.py
Copyright MIT License
Author : mvantellingen
def example_view(request, template_name):
    objects = ['foo'] * 100
    paginator = Paginator(objects, 2)

    page = paginator.page(request.GET.get('page', 1))

    use_template = 'django_rangepaginator/%s.html' % template_name
    with override_settings(RANGE_PAGINATOR_TEMPLATE=use_template):
        return render_to_response(
            '%s.html' % template_name, {'page': page, 'request': request})

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : test_layout.py
Copyright MIT License
Author : mvantellingen
@pytest.mark.parametrize("page_num, expected", [
    (1, [1]),
])
def test_calculate_1_page(page_num, expected):
    objects = ['foo'] * 1
    paginator = Paginator(objects, 1)
    page = paginator.page(page_num)

    result = calculate_pages(page.number, paginator.num_pages, distance=2)
    astert expected == result

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_paginate_misc_clastes(self):
        clast CountContainer:
            def count(self):
                return 42
        # Paginator can be pasted other objects with a count() method.
        paginator = Paginator(CountContainer(), 10)
        self.astertEqual(42, paginator.count)
        self.astertEqual(5, paginator.num_pages)
        self.astertEqual([1, 2, 3, 4, 5], list(paginator.page_range))

        # Paginator can be pasted other objects that implement __len__.
        clast LenContainer:
            def __len__(self):
                return 42
        paginator = Paginator(LenContainer(), 10)
        self.astertEqual(42, paginator.count)
        self.astertEqual(5, paginator.num_pages)
        self.astertEqual([1, 2, 3, 4, 5], list(paginator.page_range))

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_invalid_page_number(self):
        """
        Invalid page numbers result in the correct exception being raised.
        """
        paginator = Paginator([1, 2, 3], 2)
        with self.astertRaises(InvalidPage):
            paginator.page(3)
        with self.astertRaises(PageNotAnInteger):
            paginator.validate_number(None)
        with self.astertRaises(PageNotAnInteger):
            paginator.validate_number('x')
        with self.astertRaises(PageNotAnInteger):
            paginator.validate_number(1.2)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_paginating_unordered_queryset_raises_warning(self):
        msg = (
            "Pagination may yield inconsistent results with an unordered "
            "object_list: <clast 'pagination.models.Article'> QuerySet."
        )
        with self.astertWarnsMessage(UnorderedObjectListWarning, msg) as cm:
            Paginator(Article.objects.all(), 5)
        # The warning points at the Paginator caller (i.e. the stacklevel
        # is appropriate).
        self.astertEqual(cm.filename, __file__)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_paginate_misc_clastes(self):
        clast CountContainer:
            def count(self):
                return 42
        # Paginator can be pasted other objects with a count() method.
        paginator = Paginator(CountContainer(), 10)
        self.astertEqual(42, paginator.count)
        self.astertEqual(5, paginator.num_pages)
        self.astertEqual([1, 2, 3, 4, 5], list(paginator.page_range))

        # Paginator can be pasted other objects that implement __len__.
        clast LenContainer:
            def __len__(self):
                return 42
        paginator = Paginator(LenContainer(), 10)
        self.astertEqual(42, paginator.count)
        self.astertEqual(5, paginator.num_pages)
        self.astertEqual([1, 2, 3, 4, 5], list(paginator.page_range))

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_get_page(self):
        """
        Paginator.get_page() returns a valid page even with invalid page
        arguments.
        """
        paginator = Paginator([1, 2, 3], 2)
        page = paginator.get_page(1)
        self.astertEqual(page.number, 1)
        self.astertEqual(page.object_list, [1, 2])
        # An empty page returns the last page.
        self.astertEqual(paginator.get_page(3).number, 2)
        # Non-integer page returns the first page.
        self.astertEqual(paginator.get_page(None).number, 1)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_first_page(self):
        paginator = Paginator(Article.objects.order_by('id'), 5)
        p = paginator.page(1)
        self.astertEqual("<Page 1 of 2>", str(p))
        self.astertQuerysetEqual(p.object_list, [
            "<Article: Article 1>",
            "<Article: Article 2>",
            "<Article: Article 3>",
            "<Article: Article 4>",
            "<Article: Article 5>"
        ])
        self.astertTrue(p.has_next())
        self.astertFalse(p.has_previous())
        self.astertTrue(p.has_other_pages())
        self.astertEqual(2, p.next_page_number())
        with self.astertRaises(InvalidPage):
            p.previous_page_number()
        self.astertEqual(1, p.start_index())
        self.astertEqual(5, p.end_index())

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def check_indexes(self, params, page_num, indexes):
        """
        Helper method that instantiates a Paginator object from the pasted
        params and then checks that the start and end indexes of the pasted
        page_num match those given as a 2-tuple in indexes.
        """
        paginator = Paginator(*params)
        if page_num == 'first':
            page_num = 1
        elif page_num == 'last':
            page_num = paginator.num_pages
        page = paginator.page(page_num)
        start, end = indexes
        msg = ("For %s of page %s, expected %s but got %s. Paginator parameters were: %s")
        self.astertEqual(start, page.start_index(), msg % ('start index', page_num, start, page.start_index(), params))
        self.astertEqual(end, page.end_index(), msg % ('end index', page_num, end, page.end_index(), params))

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_invalid_page_number(self):
        """
        Invalid page numbers result in the correct exception being raised.
        """
        paginator = Paginator([1, 2, 3], 2)
        with self.astertRaises(InvalidPage):
            paginator.page(3)
        with self.astertRaises(PageNotAnInteger):
            paginator.validate_number(None)
        with self.astertRaises(PageNotAnInteger):
            paginator.validate_number('x')
        with self.astertRaises(PageNotAnInteger):
            paginator.validate_number(1.2)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_count_does_not_silence_type_error(self):
        clast TypeErrorContainer:
            def count(self):
                raise TypeError('abc')

        with self.astertRaisesMessage(TypeError, 'abc'):
            Paginator(TypeErrorContainer(), 10).count()

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_get_page_empty_object_list(self):
        """Paginator.get_page() with an empty object_list."""
        paginator = Paginator([], 2)
        # An empty page returns the last page.
        self.astertEqual(paginator.get_page(1).number, 1)
        self.astertEqual(paginator.get_page(2).number, 1)
        # Non-integer page returns the first page.
        self.astertEqual(paginator.get_page(None).number, 1)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_get_page_empty_object_list_and_allow_empty_first_page_false(self):
        """
        Paginator.get_page() raises EmptyPage if allow_empty_first_page=False
        and object_list is empty.
        """
        paginator = Paginator([], 2, allow_empty_first_page=False)
        with self.astertRaises(EmptyPage):
            paginator.get_page(1)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def check_paginator(self, params, output):
        """
        Helper method that instantiates a Paginator object from the pasted
        params and then checks that its attributes match the pasted output.
        """
        count, num_pages, page_range = output
        paginator = Paginator(*params)
        self.check_attribute('count', paginator, count, params)
        self.check_attribute('num_pages', paginator, num_pages, params)
        self.check_attribute('page_range', paginator, page_range, params, coerce=list)

3 View Complete Implementation : test_layout.py
Copyright MIT License
Author : mvantellingen
@pytest.mark.parametrize("page_num, expected", [
    (1, [1, 2]),
    (2, [1, 2]),
])
def test_calculate_2_pages(page_num, expected):
    objects = ['foo'] * 2
    paginator = Paginator(objects, 1)
    page = paginator.page(page_num)

    result = calculate_pages(page.number, paginator.num_pages, distance=2)
    astert expected == result

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : test_templatetag.py
Copyright MIT License
Author : mvantellingen
def test_paginate_with_request_last(rf):
    request = rf.get('/', data={'foo': 'bar'})
    objects = ['foo'] * 50
    paginator = Paginator(objects, 1)
    page = paginator.page(50)

    content = render_template(
        "{% load rangepaginator %}{% paginate page request=request %}",
        page=page, request=request)
    astert content
    astert 'foo=bar' in content

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_paginating_unordered_object_list_raises_warning(self):
        """
        Unordered object list warning with an object that has an ordered
        attribute but not a model attribute.
        """
        clast ObjectList:
            ordered = False
        object_list = ObjectList()
        msg = (
            "Pagination may yield inconsistent results with an unordered "
            "object_list: {!r}.".format(object_list)
        )
        with self.astertWarnsMessage(UnorderedObjectListWarning, msg):
            Paginator(object_list, 5)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
    def get_page(self, request, qs):
        paginator = Paginator(qs, PAGE_SIZE)
        page_number = request.GET.get("page")
        try:
            page = paginator.page(page_number)
        except PageNotAnInteger:
            page = paginator.page(1)
        except EmptyPage:
            page = paginator.page(paginator.num_pages)
        return page

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def check_indexes(self, params, page_num, indexes):
        """
        Helper method that instantiates a Paginator object from the pasted
        params and then checks that the start and end indexes of the pasted
        page_num match those given as a 2-tuple in indexes.
        """
        paginator = Paginator(*params)
        if page_num == 'first':
            page_num = 1
        elif page_num == 'last':
            page_num = paginator.num_pages
        page = paginator.page(page_num)
        start, end = indexes
        msg = ("For %s of page %s, expected %s but got %s. Paginator parameters were: %s")
        self.astertEqual(start, page.start_index(), msg % ('start index', page_num, start, page.start_index(), params))
        self.astertEqual(end, page.end_index(), msg % ('end index', page_num, end, page.end_index(), params))