Django

Code

Ticket #1795 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

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

Reported by: polarcowz@gmail.com Assigned to: nobody
Milestone: Component: Generic views
Version: SVN Keywords: pagination
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

paginator.py.diff (1.0 kB) - added by polarcowz@gmail.com on 05/07/06 12:00:56.
Paginator.py Patch
list_detail.py.diff (462 bytes) - added by polarcowz@gmail.com on 05/07/06 12:01:31.
List_detail.py Patch
1795.diff (2.4 kB) - added by Marc Fargas <telenieko@telenieko.com> on 05/20/07 17:02:16.
Uniffied diff (code, test, docs)

Change History

05/07/06 12:00:56 changed by polarcowz@gmail.com

  • attachment paginator.py.diff added.

Paginator.py Patch

05/07/06 12:01:31 changed by polarcowz@gmail.com

  • attachment list_detail.py.diff added.

List_detail.py Patch

05/07/06 13:45:17 changed 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.

06/02/06 00:27:35 changed by adrian

  • owner changed from jacob to adrian.
  • status changed from new to assigned.

07/03/06 02:11:05 changed by anonymous

  • severity changed from normal to minor.
  • component changed from Generic views to Documentation.
  • priority changed from normal to lowest.
  • version changed from SVN to 0.91.
  • milestone set to Version 0.93.
  • type changed from enhancement to task.

07/31/06 09:59:27 changed by anonymous

  • priority changed from lowest to normal.
  • type changed from task to enhancement.
  • component changed from Documentation to Generic views.
  • severity changed from minor to normal.

08/13/06 00:36:36 changed by Gary Wilson <gary.wilson@gmail.com>

  • milestone changed from Version 0.93 to Version 1.0.

0.93 has come and gone.

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted

02/17/07 04:01:24 changed by Simon G. <dev@simon.net.nz>

  • needs_docs set to 1.
  • version changed from 0.91 to SVN.
  • stage changed from Unreviewed to Ready for checkin.

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.

02/25/07 11:09:12 changed by jacob

  • stage changed from Ready for checkin to Accepted.

Needs documentation; otherwise +1 from me.

05/20/07 17:02:16 changed by Marc Fargas <telenieko@telenieko.com>

  • attachment 1795.diff added.

Uniffied diff (code, test, docs)

05/20/07 17:03:23 changed by Marc Fargas <telenieko@telenieko.com>

  • needs_docs deleted.
  • 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.

09/13/07 20:01:03 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

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


Add/Change #1795 ([patch] Addition of page_range in paginator.py and generic.list_detail.py)




Change Properties
Action