Opened 10 years ago

Closed 9 years ago

#1795 closed enhancement (fixed)

[patch] Addition of page_range in paginator.py and generic.list_detail.py

Reported by: polarcowz@… Owned by: nobody
Component: Generic views Version: master
Severity: normal Keywords: pagination
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When using generic views, the desired effect would be:

{% if is_paginated %}
<div class="tablecontrols">

{% for page_number in page_range %}

{% ifequal page_number page %}

{{ page_number }}

{% else %}

<a href="/myapp/clients/{{ page_number }}/" title="Go to page {{ page_number }}">{{ page_number }}</a>

{% endifequal %}

{% endfor %}

</div>
{% endif %}

to dump out a page list like:

[1] [2] [3] [4] [5] [6]

Since some searching turned up no way to do this within the view and I imagine this to be a common problem, I patched "django/core/paginator.py" and "django/views/generic/list_detail.py" to incorporate a new context variable, "page_range". Paginator simply generates a 1-based range up to the total pages. Attached are the patch files.

Attachments (3)

paginator.py.diff (1.0 KB) - added by polarcowz@… 10 years ago.
Paginator.py Patch
list_detail.py.diff (462 bytes) - added by polarcowz@… 10 years ago.
List_detail.py Patch
1795.diff (2.4 KB) - added by Marc Fargas <telenieko@…> 9 years ago.
Uniffied diff (code, test, docs)

Download all attachments as: .zip

Change History (13)

Changed 10 years ago by polarcowz@…

Attachment: paginator.py.diff added

Paginator.py Patch

Changed 10 years ago by polarcowz@…

Attachment: list_detail.py.diff added

List_detail.py Patch

comment:1 Changed 10 years ago by Jure Cuhalev

Yesterday I was having the same problem when I tried implementing that. In the end I looked how the django admin interface does it and copied bits of that code into my templatetag.

The "problem" with generating pages like this is that if you have hundreds of pages your page list will be too long and since I haven't found templatetag for {% ifbigger %} or {% ifsmaller %} you can't actually limit page_range to a usable range.

I would recommend extending it to actually accept two extra optional parameters that would also give range inside which there should be page range. Otherwise I think this is great idea and would quite simplify this.

comment:2 Changed 10 years ago by Adrian Holovaty

Owner: changed from Jacob to Adrian Holovaty
Status: newassigned

comment:3 Changed 10 years ago by anonymous

Component: Generic viewsDocumentation
milestone: Version 0.93
priority: normallowest
Severity: normalminor
Type: enhancementtask
Version: SVN0.91

comment:4 Changed 10 years ago by anonymous

Component: DocumentationGeneric views
priority: lowestnormal
Severity: minornormal
Type: taskenhancement

comment:5 Changed 10 years ago by Gary Wilson <gary.wilson@…>

milestone: Version 0.93Version 1.0

0.93 has come and gone.

comment:6 Changed 10 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:7 Changed 10 years ago by Simon G. <dev@…>

Needs documentation: set
Triage Stage: UnreviewedReady for checkin
Version: 0.91SVN

I've marked this as Ready-for-checkin as I think it's fairly straight-forward and adds some useful functionality, but it'll need docs.

comment:8 Changed 10 years ago by Jacob

Triage Stage: Ready for checkinAccepted

Needs documentation; otherwise +1 from me.

Changed 9 years ago by Marc Fargas <telenieko@…>

Attachment: 1795.diff added

Uniffied diff (code, test, docs)

comment:9 Changed 9 years ago by Marc Fargas <telenieko@…>

Needs documentation: unset
Triage Stage: AcceptedReady for checkin

Pagination is currently only explianed in generic_views so I added documentation there.
I also added a small test. Patch should be ready as per older comments that's the only missing thing.

comment:10 Changed 9 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [6146]) Fixed #1795 -- Added page_range to paginators in generic list views. Thanks to polarcowz@… and Marc Fargas <telenieko@…> for the patch.

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