Opened 3 years ago

Closed 2 years ago

#28032 closed Cleanup/optimization (fixed)

Add Paginator.get_page() to abstract away pagination boilerplate handling of invalid pages

Reported by: Ian Foote Owned by: Sami J. Lehtinen
Component: Core (Other) Version: master
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 Ian Foote)

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 Changed 3 years ago by Ian Foote

Description: modified (diff)

comment:2 Changed 3 years ago by Ian Foote

Description: modified (diff)

comment:3 Changed 3 years ago by Sami J. Lehtinen

Owner: changed from nobody to Sami J. Lehtinen
Status: newassigned

comment:4 Changed 3 years ago by Sami J. Lehtinen

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.

comment:5 Changed 3 years ago by Sami J. Lehtinen

Triage Stage: UnreviewedAccepted

comment:6 Changed 3 years ago by Sami J. Lehtinen

Has patch: set

comment:7 Changed 2 years ago by Tim Graham

Summary: Abstract away pagination boilerplateAdd Paginator.get_page() to abstract away pagination boilerplate handling of invalid pages
Triage Stage: AcceptedReady for checkin

comment:8 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 407c124:

Fixed #28032 -- Added Paginator.get_page().

Moved boilerplate from docs to a method.

Note: See TracTickets for help on using tickets.
Back to Top