[Django] #25513: Paginator support for large page counts

61 views
Skip to first unread message

Django

unread,
Oct 6, 2015, 9:41:54 AM10/6/15
to django-...@googlegroups.com
#25513: Paginator support for large page counts
------------------------------+-----------------------
Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.9a1
Severity: Normal | Keywords: paginator
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+-----------------------
For large page counts I miss a standard way to display only interesting
blocks of page links in the paginator. I guess Django should include one.

What do you think about integrating my implementation to
{{{django.core.paginator.Page}}} drafted below?
**Template example at the bottom.**

{{{#!python
from django.core.paginator import Paginator, Page

class EllipsisPaginator(Paginator):
def __init__(self, *args, **kwargs):
# number of page links to always display after the first page
self.start_wing = kwargs.pop('start_wing', 1)
# number of page links to always display around the current page
self.island_wings = kwargs.pop('island_wings', 2)
# number of page links to always display before the last page
self.end_wing = kwargs.pop('end_wing', 1)

super(EllipsisPaginator, self).__init__(*args, **kwargs)

def _get_page(self, *args, **kwargs):
return EllipsisPage(*args, **kwargs)


class EllipsisPage(Page):
def pages_with_ellipsis(self):
"""
Generates the list of page numbers for large page counts.
Yields '...' where the range of links should be omitted.

>>> pp = EllipsisPaginator(object_list=range(38), per_page=3)
>>> list(pp.page(1).pages_with_ellipsis())
[1, 2, 3, '...', 12, 13]
>>> list(pp.page(2).pages_with_ellipsis())
[1, 2, 3, 4, '...', 12, 13]
>>> list(pp.page(3).pages_with_ellipsis())
[1, 2, 3, 4, 5, '...', 12, 13]
>>> list(pp.page(4).pages_with_ellipsis())
[1, 2, 3, 4, 5, 6, '...', 12, 13]
>>> list(pp.page(5).pages_with_ellipsis())
[1, 2, 3, 4, 5, 6, 7, '...', 12, 13]
>>> list(pp.page(6).pages_with_ellipsis())
[1, 2, 3, 4, 5, 6, 7, 8, '...', 12, 13]
>>> list(pp.page(7).pages_with_ellipsis())
[1, 2, '...', 5, 6, 7, 8, 9, '...', 12, 13]
>>> list(pp.page(8).pages_with_ellipsis())
[1, 2, '...', 6, 7, 8, 9, 10, 11, 12, 13]
>>> list(pp.page(9).pages_with_ellipsis())
[1, 2, '...', 7, 8, 9, 10, 11, 12, 13]
>>> list(pp.page(10).pages_with_ellipsis())
[1, 2, '...', 8, 9, 10, 11, 12, 13]
>>> list(pp.page(11).pages_with_ellipsis())
[1, 2, '...', 9, 10, 11, 12, 13]
>>> list(pp.page(12).pages_with_ellipsis())
[1, 2, '...', 10, 11, 12, 13]
>>> list(pp.page(13).pages_with_ellipsis())
[1, 2, '...', 11, 12, 13]
"""
num = 1

end_of_start_wing = min(self.paginator.num_pages,
self.paginator.start_wing+1)

for num in xrange(1, end_of_start_wing+1):
yield num

island_start = self.number - self.paginator.island_wings

if num < island_start-2:
yield '...'
num = island_start
else:
num += 1

island_end = min(self.paginator.num_pages, self.number +
self.paginator.island_wings)

for num in xrange(num, island_end+1):
yield num

start_of_end_wing = self.paginator.num_pages -
self.paginator.end_wing

if num < start_of_end_wing-2:
yield '...'
num = start_of_end_wing
else:
num += 1

for num in xrange(num, self.paginator.num_pages+1):
yield num
}}}

Usage in the template:
{{{
<ul class="pagination">
<li rel="prev">
<a {% if page.has_previous %}href="?page={{
page.previous_page_number }}"{% endif %}>
Previous
</a>
</li>

{% for pg in page.pages_with_ellipsis %}

{% if pg != '...' %}
<li {% if pg == page.number %}class="active"{% endif %}>
<a {% if pg != page.number %}href="?page={{ pg }}"{% endif
%}>
{{ pg }}
</a>
</li>
{% else %}
<li><span>&hellip;</span></li>
{% endif %}

{% endfor %}

<li rel="next" {% if page.has_next %}class="highlight"{% endif %}>
<a {% if page.has_next %}href="?page={{ page.next_page_number
}}"{% endif %}>
Next
</a>
</li>
</ul>
}}}

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

Django

unread,
Oct 6, 2015, 9:45:15 AM10/6/15
to django-...@googlegroups.com
#25513: Paginator support for large page counts
--------------------------+----------------------------

Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.9a1
Severity: Normal | Resolution:

Keywords: paginator | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------+----------------------------
Changes (by Tuttle):

* Attachment "shot-20151006-1543.png" added.

A screenshot of the paginator.

Django

unread,
Oct 6, 2015, 9:46:22 AM10/6/15
to django-...@googlegroups.com
#25513: Paginator support for large page counts
------------------------------+--------------------------------------

Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.9a1
Severity: Normal | Resolution:

Keywords: paginator | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Tuttle):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Attached is the screenshot of how it can look.

The method is a simple and effetcive Python generator jumping over
iteresting blocks of pages.

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

Django

unread,
Oct 6, 2015, 10:45:50 AM10/6/15
to django-...@googlegroups.com
#25513: Paginator support for large page counts
------------------------------+--------------------------------------

Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.9a1
Severity: Normal | Resolution:

Keywords: paginator | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by timgraham):

The admin
[https://github.com/django/django/blob/6afa6818fcf25665bbf61f0921c8c8c6fa8f223e/django/contrib/admin/templatetags/admin_list.py#L48-L92
contains a similar paginator] in the form of a template tag. Maybe it
would be worth trying to refactoring that into `django.core.paginator` so
it's more easily reuseable. I'm not sure how well the code will
generalize.

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

Django

unread,
Oct 9, 2015, 2:26:48 PM10/9/15
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
------------------------------+------------------------------------

Reporter: Tuttle | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by timgraham):

* version: 1.9a1 => master
* stage: Unreviewed => Accepted


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

Django

unread,
Dec 21, 2015, 6:13:16 AM12/21/15
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
------------------------------+------------------------------------
Reporter: Tuttle | Owner: sasha0
Type: New feature | Status: assigned

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by sasha0):

* owner: nobody => sasha0
* status: new => assigned


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

Django

unread,
Dec 23, 2015, 3:59:27 PM12/23/15
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
------------------------------+------------------------------------
Reporter: Tuttle | Owner: sasha0
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by sasha0):

* has_patch: 0 => 1


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

Django

unread,
Dec 23, 2015, 5:56:54 PM12/23/15
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
------------------------------+------------------------------------
Reporter: Tuttle | Owner: sasha0
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by timgraham):

* needs_docs: 0 => 1


Comment:

Looks like it's on the right track, but the new class should be documented
too.

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

Django

unread,
Aug 22, 2018, 11:57:31 AM8/22/18
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
------------------------------+-----------------------------------------
Reporter: Vlada Macek | Owner: Sasha Gaevsky

Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+-----------------------------------------
Changes (by Tim Graham):

* needs_docs: 1 => 0


Comment:

[https://github.com/django/django/pull/10328 PR]

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

Django

unread,
Aug 23, 2018, 10:00:46 AM8/23/18
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
------------------------------+-----------------------------------------
Reporter: Vlada Macek | Owner: Sasha Gaevsky
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
------------------------------+-----------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


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

Django

unread,
Jul 9, 2020, 5:43:29 PM7/9/20
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
-------------------------------------+-------------------------------------
Reporter: Vlada Macek | Owner: Nick Pope

Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator, ellipsis | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* keywords: paginator => paginator, ellipsis
* needs_better_patch: 1 => 0
* owner: Sasha Gaevsky => Nick Pope


Comment:

Updated with a new [https://github.com/django/django/pull/13173 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/25513#comment:9>

Django

unread,
Aug 6, 2020, 5:56:42 AM8/6/20
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
-------------------------------------+-------------------------------------
Reporter: Vlada Macek | Owner: Nick Pope
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator, ellipsis | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25513#comment:10>

Django

unread,
Aug 6, 2020, 6:39:32 AM8/6/20
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
-------------------------------------+-------------------------------------
Reporter: Vlada Macek | Owner: Nick Pope
Type: New feature | Status: closed

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

Keywords: paginator, ellipsis | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton@…>):

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


Comment:

In [changeset:"0a306f7da668e53af2516bfad759b52d6c650b69" 0a306f7]:
{{{
#!CommitTicketReference repository=""
revision="0a306f7da668e53af2516bfad759b52d6c650b69"
Fixed #25513 -- Extracted admin pagination to
Paginator.get_elided_page_range().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25513#comment:13>

Django

unread,
Aug 6, 2020, 6:39:33 AM8/6/20
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
-------------------------------------+-------------------------------------
Reporter: Vlada Macek | Owner: Nick Pope
Type: New feature | Status: assigned

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator, ellipsis | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton@…>):

In [changeset:"b203ec70fd7ffc4027380940157d1cf9c9e588ad" b203ec70]:
{{{
#!CommitTicketReference repository=""
revision="b203ec70fd7ffc4027380940157d1cf9c9e588ad"
Refs #25513 -- Adjusted admin pagination to be 1-indexed.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25513#comment:11>

Django

unread,
Aug 6, 2020, 6:39:34 AM8/6/20
to django-...@googlegroups.com
#25513: Refactor the admin paginator customizations to make them reuseable
-------------------------------------+-------------------------------------
Reporter: Vlada Macek | Owner: Nick Pope
Type: New feature | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: paginator, ellipsis | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton@…>):

In [changeset:"f35840c19664fed7b6bc4cf561bf0b6fd1a3b463" f35840c1]:
{{{
#!CommitTicketReference repository=""
revision="f35840c19664fed7b6bc4cf561bf0b6fd1a3b463"
Refs #25513 -- Fixed admin pagination elision bounds.

It doesn't make sense to elide a single page number which could be a
clickable link to that page. We only want to elide two or more pages.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25513#comment:12>

Reply all
Reply to author
Forward
0 new messages