#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 , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Version: | 2.0 → master |
comment:2 by , 6 years ago
comment:3 by , 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.)
comment:5 by , 6 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Summary: | Insert a new method part_page_range for class Page in django.core.paginator.py → Add 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.
comment:6 by , 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 , 3 years ago
Resolution: | wontfix → duplicate |
---|
I'm not understanding the purpose of the new method. Can you demonstrate example usage? The patch would also required tests and documentation.