[Django] #29589: Insert a new method part_page_range for class Page in django.core.paginator.py

6 views
Skip to first unread message

Django

unread,
Jul 24, 2018, 6:45:28 AM7/24/18
to django-...@googlegroups.com
#29589: Insert a new method part_page_range for class Page in
django.core.paginator.py
----------------------------------------+------------------------
Reporter: BobDu | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
Class `Pagination` have a attribute `page_range`,
it's very useful when I want to write the other page link in the html.
We only need write in html like

{{{
<!-- contacts is a instance of Page class -->
{% for p in contacts.paginator.page_range %}
<li>
<a href="{% url 'admin_user_index' %}?&page={{ p }}">
{{ p }}
</a>
</li>
{% endfor %}
}}}

But, when the pages is too more, for example 1000, Things are going to get
scary.

So, I suggest insert a method `part_page_range()` for class Page.

For example,
When the `contacts.paginator.num_pages` `=1000`,
and the `contacts.number` `=500`,
I can use the

{{{
contacts.part_page_range(5)
}}}

to acquire a range instance `range(498, 503)`.
I think Django will be more handy after insert this method.

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

Django

unread,
Jul 24, 2018, 7:00:08 AM7/24/18
to django-...@googlegroups.com
#29589: Insert a new method part_page_range for class Page in
django.core.paginator.py
------------------------------+--------------------------------------
Reporter: BobDu | Owner: BobDu
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by BobDu):

* status: new => assigned
* owner: nobody => BobDu
* version: 2.0 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:1>

Django

unread,
Jul 24, 2018, 6:29:16 PM7/24/18
to django-...@googlegroups.com
#29589: Insert a new method part_page_range for class Page in
django.core.paginator.py
------------------------------+--------------------------------------
Reporter: BobDu | Owner: BobDu
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by Tim Graham):

I'm not understanding the purpose of the new method. Can you demonstrate
example usage? The patch would also required tests and documentation.

--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:2>

Django

unread,
Jul 26, 2018, 5:07:23 AM7/26/18
to django-...@googlegroups.com
#29589: Insert a new method part_page_range for class Page in
django.core.paginator.py
------------------------------+--------------------------------------
Reporter: BobDu | Owner: BobDu
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by Carlton Gibson):

The idea here is to generate a subset of page links for a navigation aid
right?

Something like (in HTML links):

{{{

1, 2, ... 498, 499, 500, 501, 502, 503, ... 9999, 1000
}}}

Rather than just outputting all 1000 links at once.

First question is, is this something we should add in core? (Maybe. Not
immediately sure what to say.)

But more, are there already community solutions that do this.

Django REST Framework provides utilities that do just this for the
pagination of it's Browsable API templates.
(See methods called from [https://github.com/encode/django-rest-
framework/blob/f404fda29c3c88e344db20f85cab7c51ef44ccdf/rest_framework/pagination.py#L255-L273
`PageNumberPagination.get_html_context()`].)

I imagine there will be other solutions also built around Django's
`Paginator`. Before doing anything in core it would be good to consider
what those are(?) (Even if that's only for implementation ideas.)

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

Django

unread,
Jul 27, 2018, 9:13:54 AM7/27/18
to django-...@googlegroups.com
#29589: Insert a new method part_page_range for class Page in
django.core.paginator.py
------------------------------+--------------------------------------
Reporter: BobDu | Owner: BobDu
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by Tim Graham):

Solved by #25513?

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

Django

unread,
Jul 28, 2018, 4:23:56 PM7/28/18
to django-...@googlegroups.com
#29589: Add django.core.paginator.Page.part_page_range() method

------------------------------+--------------------------------------
Reporter: BobDu | Owner: BobDu
Type: New feature | Status: closed

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

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Tim Graham):

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


Comment:

Discussion can continue but closing for now as it's not immediately
obvious to me that the proposed method is suitable.

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

Django

unread,
Nov 23, 2021, 2:03:54 AM11/23/21
to django-...@googlegroups.com
#29589: Add django.core.paginator.Page.part_page_range() method
------------------------------+--------------------------------------
Reporter: BobDu | Owner: BobDu
Type: New feature | Status: closed
Component: Core (Other) | Version: dev
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by BobDu):

Replying to [comment:4 Tim Graham]:
> Solved by #25513?
Yes, I saw that a similar feature was merged in #25513 to solve the
problem. Thanks the community’s support

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

Django

unread,
Nov 23, 2021, 2:04:31 AM11/23/21
to django-...@googlegroups.com
#29589: Add django.core.paginator.Page.part_page_range() method
------------------------------+--------------------------------------
Reporter: BobDu | Owner: BobDu
Type: New feature | Status: closed
Component: Core (Other) | Version: dev
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by BobDu):

* resolution: wontfix => duplicate


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

Reply all
Reply to author
Forward
0 new messages