Opened 18 years ago

Closed 16 years ago

#1795 closed enhancement (fixed)

[patch] Addition of page_range in and

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


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 %}

{% 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/" and "django/views/generic/" 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) (1.0 KB) - added by polarcowz@… 18 years ago. Patch (462 bytes) - added by polarcowz@… 18 years ago. 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)

Changed 18 years ago by polarcowz@…

Attachment: added Patch

Changed 18 years ago by polarcowz@…

Attachment: added Patch

comment:1 Changed 18 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 18 years ago by Adrian Holovaty

Owner: changed from Jacob to Adrian Holovaty
Status: newassigned

comment:3 Changed 17 years ago by anonymous

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

comment:4 Changed 17 years ago by anonymous

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

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

milestone: Version 0.93Version 1.0

0.93 has come and gone.

comment:6 Changed 17 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:7 Changed 17 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 17 years ago by Jacob

Triage Stage: Ready for checkinAccepted

Needs documentation; otherwise +1 from me.

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

Attachment: 1795.diff added

Uniffied diff (code, test, docs)

comment:9 Changed 17 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 16 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