Opened 17 years ago

Closed 14 years ago

#3169 closed enhancement (wontfix)

A template tag for listing/linking to nearby pages in pagination should be provided.

Reported by: Grimboy Owned by: nobody
Component: Template system Version: dev
Severity: normal Keywords: sprintsept14
Cc: gary.wilson@…, frankie@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

object_list should pass a list of pages nearby so an index of links can be created. A list of links to pages near by the current page are is a common feature of pagination. So it seems sensible to implement it in this generic view. I understand generic views are meant to be simple but the majority of pagination has this feature and I would count it as a core feature of pagination.

Attachments (4)

page_list.diff (2.9 KB ) - added by Grimboy 17 years ago.
pagelist_tag.diff (10.0 KB ) - added by frankie@… 17 years ago.
pagelistv2.diff (10.1 KB ) - added by frankie@… 17 years ago.
Proofread the documentation
pagelistv3.diff (10.1 KB ) - added by frankie@… 17 years ago.
Fixed stupidity.

Download all attachments as: .zip

Change History (20)

by Grimboy, 17 years ago

Attachment: page_list.diff added

comment:1 by Gary Wilson <gary.wilson@…>, 17 years ago

Cc: gary.wilson@… added
Type: defectenhancement

This seems like something that would make a nice template tag, instead of changing stuff in the generic view.

comment:2 by frankie@…, 17 years ago

Component: Generic viewsTemplate system
Owner: changed from Jacob to Adrian Holovaty
Summary: [patch] object_list should pass a list of pages nearby so an index of links can be created.A template tag for listing/linking to nearby pages in pagination should be provided.

Thanks your thoughts. I'm inclined to agree. It does perhaps seem a little out of place in the generic view.

As for a template tag. Which of these do you think would be better?

<ul>
    {% pagelist as page_list surround 5 %}
    {% for page_num in page_list %}
        <li>{{ page_num }}</li>
    {% endfor %}
</ul>

Or

<ul>
    {% pagelist as page_num surround 5 %}
        <li>{{ page_num }}</li>
    {% endpagelist %}
</ul>

Which could be expanded to optionally include the first few and last few page numbers (at the edges).

<ul>
    {% pagelist as page_num surround 5 edges 3 %}
        <li>{{ page_num }}</li>
    {% seperator %}
        <li>...</li>
    {% endpagelist %}
</ul>

I'm inclined towards the second but perhaps it's a bit weird or over the top. Please let me know what you think. Thanks.

comment:3 by frankie@…, 17 years ago

Cc: frankie@… added

comment:4 by Gary Wilson <gary.wilson@…>, 17 years ago

Well, I was thinking it could be a one liner, something like:

{% pagelist surround 5 edges 3 firstlast true %}

Of course the options would have to be worked out, but then this would use a template to display, something like:

<ul class="pagelist">
    {% if firstlast %}<li><a title="First">&lt;&lt;</a></li>{% endif %}
    {% for p in pages %}
    <li{% ifequal p page %} class="current"{% endifequal %}><a title="Page {{ p }}">{{ p }}</a></li>
    {% endfor %}
    {% if firstlast %}<li><a title="Last">&gt;&gt;</a></li>{% endif %}
</ul>

Basically, some generic template that could serve as a good default. If someone wanted to customize it, they could just override the template with one of their own.

As far as the URL target to use for the links, maybe the tag would default to using a page query string parameter, so

<a href="?page={{ p }}">

Otherwise you could specify a URL prefix in the template tag, like

{% pagelist urlprefix page %}

which would become

<a href="../{{ urlprefix }}{{ p }}">

if the prefix is relative, or

<a href="{{ urlprefix }}{{ p }}">

if the prefix is absolute.

by frankie@…, 17 years ago

Attachment: pagelist_tag.diff added

by frankie@…, 17 years ago

Attachment: pagelistv2.diff added

Proofread the documentation

comment:5 by anonymous, 17 years ago

Summary: A template tag for listing/linking to nearby pages in pagination should be provided.[patch] A template tag for listing/linking to nearby pages in pagination should be provided.

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

Triage Stage: UnreviewedDesign decision needed

comment:7 by James Bennett, 17 years ago

Keywords: sprintsept14 added

There are a ton of different snippets floating around for doing this sort of thing; I'm going to tag with the sprint keyword to get some attention here to make a decision.

by frankie@…, 17 years ago

Attachment: pagelistv3.diff added

Fixed stupidity.

comment:8 by James Bennett, 17 years ago

See alternate proposal in #4809, which was closed in favor of doing the work here.

comment:9 by deepak <deep.thukral@…>, 17 years ago

IMO this patch needs better querystring parsing like /page?q=searching&highlight=cool&page=1 .. here is a snippets which might help frankie http://dpaste.com/17864/ and here is discussion on it http://groups.google.com/group/django-developers/browse_thread/thread/93646ef6a168ad6a/1bb42300896b1403

comment:10 by frankie@…, 17 years ago

Yeah, I though about that. The only problem is that as soon as you add that you have the requirement for the template context processor django.core.context_processors.request because the only way for a template tag to get access to the request.querystring. (Well unless you add a middleware component and use thread local storage, but that's hardly an appetising proposal either.) The case of wanting to use a get key-value pair for the page (page=foo) and already having a bit of querystring going is not too hard to handle though. Each page in page_index has {{ page.number }} which can be used in combination with querystring parsing in the view to create a link in a pagelist template.

comment:11 by James Bennett, 17 years ago

See also #5425, which I'm consolidating here temporarily so we have a single place to handle pagination discussions.

comment:12 by Petr Marhoun <petr.marhoun@…>, 17 years ago

#5425 is not about pagination so I reopened it.

comment:13 by Jacob, 16 years ago

Version: SVN

comment:14 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

The page object introduced in [7306] fixes this.

comment:15 by Jacob, 16 years ago

Resolution: fixed
Status: closedreopened

Er, no, it doesn't.

comment:16 by Russell Keith-Magee, 14 years ago

Resolution: wontfix
Status: reopenedclosed
Summary: [patch] A template tag for listing/linking to nearby pages in pagination should be provided.A template tag for listing/linking to nearby pages in pagination should be provided.

Marking this wontfix; there's nothing wrong with the principle of making the common use case of pagination easier to use, but this isn't it. The template example in the provided docs should be enough to convince anyone of that. This can be revisited if someone can present an implementation that is in the wild and is getting some public use.

Note: See TracTickets for help on using tickets.
Back to Top