#28032: Abstract away pagination boilerplate
-------------------------------------+-------------------------------------
     Reporter:  Ian Foote            |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Core (Other)         |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  Pagination           |             Triage Stage:
  Paginator                          |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Ian Foote:

Old description:

> In the [https://docs.djangoproject.com/en/1.11/topics/pagination/#using-
> paginator-in-a-view 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
> [https://github.com/django/django/blob/5a6f70b4281817656db2f36c5919036d38fcce7f/django/core/paginator.py#L25
> Paginator] class, perhaps named something like {{{results_for_page}}}.

New description:

 In the [https://docs.djangoproject.com/en/1.11/topics/pagination/#using-
 paginator-in-a-view 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
 
[https://github.com/django/django/blob/5a6f70b4281817656db2f36c5919036d38fcce7f/django/core/paginator.py#L25
 Paginator] class, perhaps named something like {{{results_for_page}}}.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28032#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.24ff591bfb97e045d3f5cd0b9d25a507%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to