Login

Tag "digg"

Snippet List

Improved many-page pagination

This one was adapted from [Page numbers with ... like in Digg](http://djangosnippets.org/snippets/1441/). See that one for more reference. Digg-like page numbering using inclusion tag. Usage in template: `{% load pagination %} {% pagination yourpage %}` Inclusion template pagination.html: {% if page.has_previous %} <a href="?page={{ page.previous_page_number }}"><img src="{{ MEDIA_URL }}images/page/cyclenav_l.png" alt="Previous page" /></a> {% endif %} {% for pnum in begin %} <a href="?page={{ pnum }}"{% if page.number == pnum %} class="active"{% endif %}>{{ pnum }}</a> {% endfor %} {% if middle %} <strong>...</strong> {% for pnum in middle %} <a href="?page={{ pnum }}"{% if page.number == pnum %} class="active"{% endif %}>{{ pnum }}</a> {% endfor %} {% endif %} {% if end %} <strong>...</strong> {% for pnum in end %} <a href="?page={{ pnum }}"{% if page.number == pnum %} class="active"{% endif %}>{{ pnum }}</a> {% endfor %} {% endif %} {% if page.has_next %} <a href="?page={{ page.next_page_number }}"><img src="{{ MEDIA_URL }}images/page/cyclenav_l.png" alt="Previous page" /></a> {% endif %}` Produces: previous_img 1 2 ... 4 5 6 7 8 9 10 11 12 ... 17 18 next_img Or: 1 2 3 4 5 6 7 8 ... 17 18 next_img Or: previous_img 1 2 ... 10 11 12 13 14 15 16 17 18 next_img

  • tag
  • django
  • templatetag
  • pagination
  • digg
  • pages
Read More

yet another digg style paginator

put this code into your application's `__init__.py` it adds a mixin to the `Paginator` class that implements a digg style pagination. the mixin has just one method called `digg_page_range` that takes the current page object as the parameter. this method is an iterator which yields page numbers with `None` values representing gaps. this iterator is similar to the original paginator's method `page_range` and it can be used in your code to emit the needed markup.

  • paginator
  • digg
Read More

Digg-like pagination

My take on digg-like pagination. Save the code as 'templatetags/pagination_nav.py' in one of your apps. It relies on a 'pagination_nav.html' template. Here is a base template: {% if pages %} <div class="bottom-pagination-nav"> {% if previous_url %}<a href="{{ previous_url }}">{% else %}<span>{% endif %}&laquo; Previous{% if previous_url %}</a>{% else %}</span>{% endif %} {% for group in pages %} {% for page in group %} {% if page.current %}<span>{{ page.number }}</span>{% else %}<a href="{{ page.url }}">{{ page.number }}</a>{% endif %} {% endfor %} {% if not forloop.last %}<span>...</span>{% endif %} {% endfor %} {% if next_url %}<a href="{{ next_url }}">{% else %}<span>{% endif %}Next &raquo;{% if next_url %}</a>{% else %}</span>{% endif %} </div> {% endif %}

  • pagination
  • template-tag
  • paginator
  • digg
Read More

Page numbers with ... like in Digg

Digg-like page numbering using inclusion tag. Usage in template: {% load pagination %} {% pagination yourpage %} Inclusion template `pagination.html`: {% load i18n %} <div class="pagination"> <span class="step-links"> {% if page.has_previous %} <a href="?page={{ page.previous_page_number }}" class="previous">{% trans "previous" %}</a> {% endif %} {% for pnum in begin %} {% ifequal page.number pnum %} <span class="current">{{ pnum }}</span> {% else %} <a href="?page={{ pnum }}">{{ pnum }}</a> {% endifequal %} {% endfor %} {% if middle %} <span class="continue">...</span> {% for pnum in middle %} {% ifequal page.number pnum %} <span class="current">{{ pnum }}</span> {% else %} <a href="?page={{ pnum }}">{{ pnum }}</a> {% endifequal %} {% endfor %} {% endif %} {% if end %} <span class="continue">...</span> {% for pnum in end %} {% ifequal page.number pnum %} <span class="current">{{ pnum }}</span> {% else %} <a href="?page={{ pnum }}">{{ pnum }}</a> {% endifequal %} {% endfor %} {% endif %} {% if page.has_next %} <a href="?page={{ page.next_page_number }}" class="next">{% trans "next" %}</a> {% endif %} </span> </div> Produces: previous 1 2 ... 4 5 6 7 **8** 9 10 11 12 ... 17 18 next Or: **1** 2 3 4 5 6 7 8 ... 17 18 next Or: previous 1 2 ... 10 11 12 13 14 15 16 **17** 18 next

  • tag
  • django
  • templatetag
  • pagination
  • digg
  • pages
Read More

Digg-like paginator, updated

This is an updated version of http://www.djangosnippets.org/snippets/628/ now working with Django's new Paginator class, instead of the deprecated ObjectPaginator. See: http://blog.elsdoerfer.name/2008/05/26/diggpaginator-update/

  • pagination
  • paginator
  • digg
Read More

Stateful paginator, digg style

**This code will throw deprecation warnings in newer Django checkouts - see the http://www.djangosnippets.org/snippets/773/ for an improved version that should work with the recent trunk.** objects = MyModel.objects.all() paginator = DiggPaginator(objects, 10, body=6, padding=2, page=7) return render_to_response('template.html', {'paginator': paginator} {% if paginator.has_next %}{# pagelink paginator.next #}{% endif %} {% for page in paginator.page_range %} {% if not page %} ... {% else %}{# pagelink page #} {% endif %} {% endfor %} http://blog.elsdoerfer.name/2008/03/06/yet-another-paginator-digg-style/

  • pagination
  • paginator
  • digg
Read More

6 snippets posted so far.