Opened 10 years ago

Closed 9 years ago

#1795 closed enhancement (fixed)

[patch] Addition of page_range in and

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:


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@… 10 years ago. Patch (462 bytes) - added by polarcowz@… 10 years ago. 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@… Patch

Changed 10 years ago by polarcowz@… 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

  • Owner changed from jacob to adrian
  • Status changed from new to assigned

comment:3 Changed 10 years ago by anonymous

  • Component changed from Generic views to Documentation
  • milestone set to Version 0.93
  • priority changed from normal to lowest
  • Severity changed from normal to minor
  • Type changed from enhancement to task
  • Version changed from SVN to 0.91

comment:4 Changed 10 years ago by anonymous

  • Component changed from Documentation to Generic views
  • priority changed from lowest to normal
  • Severity changed from minor to normal
  • Type changed from task to enhancement

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

  • milestone changed from Version 0.93 to Version 1.0

0.93 has come and gone.

comment:6 Changed 9 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

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

  • Needs documentation set
  • Triage Stage changed from Unreviewed to Ready for checkin
  • Version changed from 0.91 to SVN

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 9 years ago by jacob

  • Triage Stage changed from Ready for checkin to Accepted

Needs documentation; otherwise +1 from me.

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

Uniffied diff (code, test, docs)

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

  • Needs documentation unset
  • Triage Stage changed from Accepted to Ready 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 russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(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