#17159: Paginator.Page() should throw an exception for invalid
[next|previous]_page_number()
--------------------------------+------------------------------------------
     Reporter:  mehta.apurva@…  |                    Owner:  mehta.apurva@…
         Type:  Bug             |                   Status:  new
    Component:  Core (Other)    |                  Version:  1.3
     Severity:  Normal          |               Resolution:
     Keywords:  paginator core  |             Triage Stage:  Accepted
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  1               |                    UI/UX:  0
--------------------------------+------------------------------------------
Changes (by julien):

 * stage:  Unreviewed => Accepted


Old description:

> 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
> >>>

New description:

 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
 =======
 {{{#!python
 >>> 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
 }}}

--

Comment:

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

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17159#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to