[Django] #28032: Abstract away pagination boilerplate

6 megtekintés
Ugrás az első olvasatlan üzenetre

Django

olvasatlan,
2017. ápr. 6. 4:09:472017. 04. 06.
– django-...@googlegroups.com
#28032: Abstract away pagination boilerplate
-------------------------------------+-------------------------------------
Reporter: Ian Foote | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core | Version: master
(Other) | Keywords: Pagination
Severity: Normal | Paginator
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

olvasatlan,
2017. ápr. 6. 4:10:232017. 04. 06.
– django-...@googlegroups.com
#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:1>

Django

olvasatlan,
2017. ápr. 6. 4:11:032017. 04. 06.
– django-...@googlegroups.com
#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

olvasatlan,
2017. ápr. 6. 4:15:272017. 04. 06.
– django-...@googlegroups.com
#28032: Abstract away pagination boilerplate
-------------------------------------+-------------------------------------
Reporter: Ian Foote | Owner: Sami J.
Type: | Lehtinen
Cleanup/optimization | Status: assigned

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
-------------------------------------+-------------------------------------
Changes (by Sami J. Lehtinen):

* owner: nobody => Sami J. Lehtinen
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28032#comment:3>

Django

olvasatlan,
2017. ápr. 6. 4:20:232017. 04. 06.
– django-...@googlegroups.com
#28032: Abstract away pagination boilerplate
-------------------------------------+-------------------------------------
Reporter: Ian Foote | Owner: Sami J.
Type: | Lehtinen
Cleanup/optimization | Status: assigned
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
-------------------------------------+-------------------------------------

Comment (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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28032#comment:4>

Django

olvasatlan,
2017. ápr. 6. 4:21:222017. 04. 06.
– django-...@googlegroups.com
#28032: Abstract away pagination boilerplate
-------------------------------------+-------------------------------------
Reporter: Ian Foote | Owner: Sami J.
Type: | Lehtinen
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: Pagination | Triage Stage: Accepted
Paginator |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sami J. Lehtinen):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/28032#comment:5>

Django

olvasatlan,
2017. ápr. 6. 6:35:452017. 04. 06.
– django-...@googlegroups.com
#28032: Abstract away pagination boilerplate
-------------------------------------+-------------------------------------
Reporter: Ian Foote | Owner: Sami J.
Type: | Lehtinen
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: Pagination | Triage Stage: Accepted
Paginator |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sami J. Lehtinen):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/8305

--
Ticket URL: <https://code.djangoproject.com/ticket/28032#comment:6>

Django

olvasatlan,
2017. szept. 5. 21:52:332017. 09. 05.
– django-...@googlegroups.com
#28032: Add Paginator.get_page() to abstract away pagination boilerplate handling
of invalid pages
-------------------------------------+-------------------------------------

Reporter: Ian Foote | Owner: Sami J.
Type: | Lehtinen
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: Pagination | Triage Stage: Ready for
Paginator | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28032#comment:7>

Django

olvasatlan,
2017. szept. 6. 14:36:222017. 09. 06.
– django-...@googlegroups.com
#28032: Add Paginator.get_page() to abstract away pagination boilerplate handling
of invalid pages
-------------------------------------+-------------------------------------

Reporter: Ian Foote | Owner: Sami J.
Type: | Lehtinen
Cleanup/optimization | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: Pagination | Triage Stage: Ready for
Paginator | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"407c1249c9a0296ec8a8d95e447bd695ca471b5e" 407c124]:
{{{
#!CommitTicketReference repository=""
revision="407c1249c9a0296ec8a8d95e447bd695ca471b5e"
Fixed #28032 -- Added Paginator.get_page().

Moved boilerplate from docs to a method.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28032#comment:8>

Válasz mindenkinek
Válasz a szerzőnek
Továbbítás
0 új üzenet