Opened 13 years ago

Last modified 12 years ago

#17159 closed New feature

Paginator.Page() should throw an exception for invalid [next|previous]_page_number() — at Version 2

Reported by: mehta.apurva@… Owned by: mehta.apurva@…
Component: Core (Other) Version: 1.3
Severity: Normal Keywords: paginator core
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Julien Phalip)

The next_page_number() and previous_page_number() currently return an incremented or decremented number without verifying if the page is in the range or not. They should instead throw an exception.

Repro Steps
=======

>>> from django.core.paginator import Paginator
>>> objects = ['john', 'paul', 'george', 'ringo', 'bill', 'gates', 'steve', 'jobs']
>>> p = Paginator(objects, 2)
>>> p.count
8
>>> p.num_pages
4
>>> p.page_range
[1, 2, 3, 4]
>>> p.page(1).has_previous()
False
>>> p.page(4).has_next()
False
>>> p.page(1).previous_page_number()  ### Should throw Exception
0   
>>> p.page(4).next_page_number() ### Should throw Exception
5

Change History (2)

comment:1 by anonymous, 13 years ago

Owner: changed from nobody to mehta.apurva@…

comment:2 by Julien Phalip, 13 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted

That makes sense. It would be a matter of calling Page.paginator.validate_number().

Note: See TracTickets for help on using tickets.
Back to Top