Opened 9 years ago
Last modified 8 years ago
#28032 closed Cleanup/optimization
Abstract away pagination boilerplate — at Version 1
| Reported by: | Ian Foote | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Normal | Keywords: | Pagination Paginator |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
In the documentation for pagination, we recommend using this boilerplate:
try:
contacts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
contacts = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
contacts = paginator.page(paginator.num_pages)
This could be abstracted away into a simple method on the Paginator class, perhaps named something like results_for_page.
Note:
See TracTickets
for help on using tickets.