Opened 19 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: | 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:
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)
Change History (13)
by , 19 years ago
Attachment: | paginator.py.diff added |
---|
comment:1 by , 19 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 , 19 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 18 years ago
Component: | Generic views → Documentation |
---|---|
milestone: | → Version 0.93 |
priority: | normal → lowest |
Severity: | normal → minor |
Type: | enhancement → task |
Version: | SVN → 0.91 |
comment:4 by , 18 years ago
Component: | Documentation → Generic views |
---|---|
priority: | lowest → normal |
Severity: | minor → normal |
Type: | task → enhancement |
comment:7 by , 18 years ago
Needs documentation: | set |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
Version: | 0.91 → 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 by , 18 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
Needs documentation; otherwise +1 from me.
comment:9 by , 18 years ago
Needs documentation: | unset |
---|---|
Triage Stage: | Accepted → 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 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Paginator.py Patch