Django

Code

Ticket #3169 (reopened)

Opened 2 years ago

Last modified 9 months ago

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

Reported by: Grimboy Assigned to: nobody
Milestone: Component: Template system
Version: SVN Keywords: sprintsept14
Cc: gary.wilson@gmail.com, frankie@grimboy.co.uk Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

page_list.diff (2.9 kB) - added by Grimboy on 12/19/06 21:17:15.
pagelist_tag.diff (10.0 kB) - added by frankie@grimboy.co.uk on 12/22/06 12:17:04.
pagelistv2.diff (10.1 kB) - added by frankie@grimboy.co.uk on 12/22/06 13:36:36.
Proofread the documentation
pagelistv3.diff (10.1 kB) - added by frankie@grimboy.co.uk on 09/16/07 13:19:46.
Fixed stupidity.

Change History

12/19/06 21:17:15 changed by Grimboy

  • attachment page_list.diff added.

12/19/06 22:06:54 changed by Gary Wilson <gary.wilson@gmail.com>

  • cc set to gary.wilson@gmail.com.
  • type changed from defect to enhancement.

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

12/20/06 10:57:46 changed by frankie@grimboy.co.uk

  • owner changed from jacob to adrian.
  • component changed from Generic views to Template system.
  • summary changed from [patch] object_list should pass a list of pages nearby so an index of links can be created. to 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.

12/20/06 13:06:22 changed by frankie@grimboy.co.uk

  • cc changed from gary.wilson@gmail.com to gary.wilson@gmail.com, frankie@grimboy.co.uk.

12/21/06 10:58:59 changed by Gary Wilson <gary.wilson@gmail.com>

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.

12/22/06 12:17:04 changed by frankie@grimboy.co.uk

  • attachment pagelist_tag.diff added.

12/22/06 13:36:36 changed by frankie@grimboy.co.uk

  • attachment pagelistv2.diff added.

Proofread the documentation

12/22/06 13:38:06 changed by anonymous

  • summary changed from A template tag for listing/linking to nearby pages in pagination should be provided. to [patch] A template tag for listing/linking to nearby pages in pagination should be provided..

02/10/07 04:53:40 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Design decision needed.

09/16/07 10:42:23 changed by ubernostrum

  • keywords set to sprintsept14.

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.

09/16/07 13:19:46 changed by frankie@grimboy.co.uk

  • attachment pagelistv3.diff added.

Fixed stupidity.

09/16/07 15:12:12 changed by ubernostrum

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

09/16/07 15:32:48 changed by deepak <deep.thukral@gmail.com>

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

09/16/07 17:00:22 changed by frankie@grimboy.co.uk

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.

09/16/07 17:12:41 changed by ubernostrum

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

09/16/07 19:53:32 changed by Petr Marhoun <petr.marhoun@gmail.com>

#5425 is not about pagination so I reopened it.

12/02/07 14:13:57 changed by jacob

  • version set to SVN.

03/19/08 11:00:40 changed by jacob

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

The page object introduced in [7306] fixes this.

03/19/08 11:02:42 changed by jacob

  • status changed from closed to reopened.
  • resolution deleted.

Er, no, it doesn't.


Add/Change #3169 ([patch] A template tag for listing/linking to nearby pages in pagination should be provided.)




Change Properties
Action