Opened 8 years ago
Closed 8 years ago
#28032 closed Cleanup/optimization (fixed)
Add Paginator.get_page() to abstract away pagination boilerplate handling of invalid pages
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
.
Change History (8)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Description: | modified (diff) |
---|
comment:3 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 8 years ago
comment:5 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:7 by , 8 years ago
Summary: | Abstract away pagination boilerplate → Add Paginator.get_page() to abstract away pagination boilerplate handling of invalid pages |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
When I last used the paginator, I needed to copy'n'paste the boilerplate code, so probably could do with an utility method. I'll take a look.