Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#29589 closed New feature (duplicate)

Add django.core.paginator.Page.part_page_range() method

Reported by: BobDu Owned by: BobDu
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (7)

comment:1 by BobDu, 6 years ago

Owner: changed from nobody to BobDu
Status: newassigned
Version: 2.0master

comment:2 by Tim Graham, 6 years ago

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

comment:3 by Carlton Gibson, 6 years ago

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 `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.)

Version 0, edited 6 years ago by Carlton Gibson (next)

comment:4 by Tim Graham, 6 years ago

Solved by #25513?

comment:5 by Tim Graham, 6 years ago

Resolution: wontfix
Status: assignedclosed
Summary: Insert a new method part_page_range for class Page in django.core.paginator.pyAdd django.core.paginator.Page.part_page_range() method

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

in reply to:  4 comment:6 by Bob Du, 3 years ago

Replying to 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

comment:7 by Bob Du, 3 years ago

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