Add Paginator.get_page() to abstract away pagination boilerplate handling of invalid pages
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)
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Owner: |
changed from nobody to Sami J. Lehtinen
|
Status: |
new → assigned
|
Triage Stage: |
Unreviewed → Accepted
|
Summary: |
Abstract away pagination boilerplate → Add Paginator.get_page() to abstract away pagination boilerplate handling of invalid pages
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
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.