Opened 14 years ago
Closed 13 years ago
#17159 closed New feature (fixed)
Paginator.Page() should throw an exception for invalid [next|previous]_page_number()
| Reported by: | Owned by: | neaf | |
|---|---|---|---|
| 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 )
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
Attachments (2)
Change History (14)
comment:1 by , 14 years ago
| Owner: | changed from to |
|---|
comment:2 by , 14 years ago
| Description: | modified (diff) |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 14 years ago
| Type: | Bug → New feature |
|---|
comment:4 by , 14 years ago
| Has patch: | set |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
Updated the functions to call Page.paginator.validate_number()
comment:5 by , 14 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
Please don't mark tickets as fixed until the fix is actually committed to the code base.
comment:6 by , 14 years ago
| Needs documentation: | set |
|---|---|
| Needs tests: | set |
Thank you. This would now need some tests and documentation (https://docs.djangoproject.com/en/dev/topics/pagination/).
comment:7 by , 14 years ago
| Owner: | changed from to |
|---|---|
| Status: | reopened → new |
by , 14 years ago
| Attachment: | ticket17159-v2.diff added |
|---|
Previous patch with tests and documentation update.
comment:8 by , 14 years ago
Attached another patch with tests and documentation.
I'm not sure if it isn't compatibility breaking change. I'm pretty sure no-one wants to display 0 and out-of-range pages but I don't know if we should throw exceptions where we haven't in the ast.
comment:9 by , 14 years ago
| Status: | new → assigned |
|---|
comment:10 by , 14 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:11 by , 14 years ago
Quick note: This is slightly backward-compatible and some release notes should be added.
comment:12 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
That makes sense. It would be a matter of calling
Page.paginator.validate_number().