Opened 18 years ago

Closed 17 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: dev
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: no UI/UX: no

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@… 18 years ago.
Paginator.py Patch
list_detail.py.diff (462 bytes ) - added by polarcowz@… 18 years ago.
List_detail.py Patch
1795.diff (2.4 KB ) - added by Marc Fargas <telenieko@…> 17 years ago.
Uniffied diff (code, test, docs)

Download all attachments as: .zip

Change History (13)

by polarcowz@…, 18 years ago

Attachment: paginator.py.diff added

Paginator.py Patch

by polarcowz@…, 18 years ago

Attachment: list_detail.py.diff added

List_detail.py Patch

comment:1 by Jure Cuhalev, 18 years ago

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 by Adrian Holovaty, 18 years ago

Owner: changed from Jacob to Adrian Holovaty
Status: newassigned

comment:3 by anonymous, 18 years ago

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

comment:4 by anonymous, 18 years ago

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

comment:5 by Gary Wilson <gary.wilson@…>, 18 years ago

milestone: Version 0.93Version 1.0

0.93 has come and gone.

comment:6 by (none), 18 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:7 by Simon G. <dev@…>, 17 years ago

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 by Jacob, 17 years ago

Triage Stage: Ready for checkinAccepted

Needs documentation; otherwise +1 from me.

by Marc Fargas <telenieko@…>, 17 years ago

Attachment: 1795.diff added

Uniffied diff (code, test, docs)

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

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 by Russell Keith-Magee, 17 years ago

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