]> git.parisson.com Git - telemeta.git/commitdiff
add paginator to item and collection listing
authoryomguy <yomguy@parisson.com>
Fri, 29 Apr 2011 22:43:38 +0000 (00:43 +0200)
committeryomguy <yomguy@parisson.com>
Fri, 29 Apr 2011 22:43:38 +0000 (00:43 +0200)
telemeta/htdocs/css/telemeta.css
telemeta/templates/telemeta/paginator.html [new file with mode: 0644]
telemeta/templates/telemeta_default/collection_list.html
telemeta/templates/telemeta_default/inc/collection_list.html
telemeta/templates/telemeta_default/inc/mediaitem_list.html
telemeta/templates/telemeta_default/mediaitem_list.html
telemeta/templates/telemeta_default/paginator.html [new file with mode: 0644]
telemeta/templatetags/paginator.py [new file with mode: 0644]
telemeta/templatetags/telemeta_utils.py

index 92f3290524e1657386876ddb6b14bc8f6affc443..5765ecfbe8b2b998e25879cbbadff04c5a2db375 100644 (file)
@@ -678,16 +678,16 @@ dl.dublincore dd.caption {
     margin-top: .7em;
     margin-bottom: .3em;
     padding: .3em 0;
-    font-size: .9em;
+    font-size: 1em;
     background-color: #fff;
     border-bottom: 1px solid #aaa;
     color: #333;
     font-weight: bold;
 }
 .pagination a {
-    background-color: #eee;
+    background-color: #fff;
     border-bottom: none;
-    font-size: .9em;
+    font-size: 1em;
     padding: .3em;
 }
 
diff --git a/telemeta/templates/telemeta/paginator.html b/telemeta/templates/telemeta/paginator.html
new file mode 100644 (file)
index 0000000..98e2779
--- /dev/null
@@ -0,0 +1 @@
+{% extends "telemeta_default/paginator.html" %}
index 20bd60e8dca14095590dc298b72efae3bbe853da..6bff068e45b00ea60580217da0f6921bd2b95764 100644 (file)
@@ -5,9 +5,9 @@
 {% block head_title %}{% trans "Media Collections" %} - {{ block.super }}{% endblock %}
 
 {% block title%}
   <h1>{% trans "Media Collections" %}</h1>
+ <h1>{% trans "Media Collections" %}</h1>
 {% endblock %}
-{% block title_buttons %} 
+{% block title_buttons %}
      <a href="{% url telemeta-collections %}" class="component_icon button icon_search">{% trans "All" %}</a>
      <a href="{% url telemeta-collections-novel %}" class="component_icon button icon_filter">{% trans "Unpublished" %}</a>
      <a href="{% url telemeta-collections-published %}" class="component_icon button icon_filter">{% trans "Published" %}</a>
index 84f7e100b8baa8551ec2b872316b70c142626af8..e81c9b3f24b1e9f0df953480cbc08a6022ae8250 100644 (file)
@@ -5,8 +5,7 @@
 <p class="pagination">
 {% blocktrans %}Collections {{ first_on_page }} to {{ last_on_page }} on {{ hits }}{% endblocktrans %}
 &nbsp;&nbsp;
-{% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %}
-{% if has_next %} <a href="?page={{ next }}&amp;{{criteria|build_query_string}}">&gt;&gt;</a> {% endif %}
+{% if is_paginated %}{% load paginator %}{% paginator 5 %}{% endif %}
 </p>
 {% endif %}
 <table class="listing">
index 6c3ae692ee3f92ca98efbfa400170b99db3b373b..01b7826a71bc1459f87fd2017b240e7949668a1b 100644 (file)
@@ -5,8 +5,7 @@
 <p class="pagination">
 {% blocktrans %}Items {{ first_on_page }} to {{ last_on_page }} on {{ hits }}{% endblocktrans %}
 &nbsp;&nbsp;
-{% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %}
-{% if has_next %} <a href="?page={{ next }}&amp;{{criteria|build_query_string}}">&gt;&gt;</a> {% endif %}
+{% if is_paginated %}{% load paginator %}{% paginator 5 %}{% endif %}
 </p>
 {% endif %}
 
index ba4c676715e2011dbefa0e4d772c46c7734f21c5..c83cc57a89b198152c16bad0d8caa8a1d03188fb 100644 (file)
@@ -5,7 +5,7 @@
 {% block head_title %}{% trans "Media Items" %} - {{ block.super }}{% endblock %}
 
 {% block title %}
   <img src="images/item.png" style="vertical-align:middle" /> <h1>{% trans "Media Items" %}</h1>
+ <img src="images/item.png" style="vertical-align:middle" /> <h1>{% trans "Media Items" %}</h1>
 {% endblock %}
 {% block title_buttons %}
     {% if user.is_authenticated and perms.telemeta.add_mediaitem %}
diff --git a/telemeta/templates/telemeta_default/paginator.html b/telemeta/templates/telemeta_default/paginator.html
new file mode 100644 (file)
index 0000000..415d5fa
--- /dev/null
@@ -0,0 +1,23 @@
+{% load i18n %}
+
+{% if has_previous %}
+    <a href="?page={{ previous }}">&lt; {% trans "Previous" %}</a>
+{% endif %}
+
+{% if show_first %}
+<a href="?page=1">1</a> ...
+{% endif %}
+{% for linkpage in page_numbers %}
+    {% ifequal linkpage page %}
+        {{ page }}
+    {% else %}
+        <a href="?page={{ linkpage }}">{{ linkpage }}</a>
+    {% endifequal %}
+{% endfor %}
+{% if show_last %}
+    ...
+    <a href="?page=last">{{ pages }}</a>
+{% endif %}
+{% if has_next %}
+    <a href="?page={{ next }}">{% trans "Next" %} &gt;</a>
+{% endif %}
diff --git a/telemeta/templatetags/paginator.py b/telemeta/templatetags/paginator.py
new file mode 100644 (file)
index 0000000..9abee1b
--- /dev/null
@@ -0,0 +1,43 @@
+from django import template
+
+register = template.Library()
+def paginator(context, adjacent_pages=2):
+    """
+    To be used in conjunction with the object_list generic view.
+
+    Adds pagination context variables for use in displaying first, adjacent and
+    last page links in addition to those created by the object_list generic
+    view.
+    
+    Thanks to  tummy.com, ltd.
+    http://www.tummy.com/Community/Articles/django-pagination/
+
+    """
+    startPage = max(context['page'] - adjacent_pages, 1)
+    if startPage <= 3: startPage = 1
+    endPage = context['page'] + adjacent_pages + 1
+    if endPage >= context['pages'] - 1: endPage = context['pages'] + 1
+    page_numbers = [n for n in range(startPage, endPage) \
+            if n > 0 and n <= context['pages']]
+    page_obj = context['page_obj']
+    paginator = context['paginator']
+
+    return {
+        'page_obj': page_obj,
+        'paginator': paginator,
+        'hits': context['hits'],
+        'results_per_page': context['results_per_page'],
+        'page': context['page'],
+        'pages': context['pages'],
+        'page_numbers': page_numbers,
+        'next': context['next'],
+        'previous': context['previous'],
+        'has_next': context['has_next'],
+        'has_previous': context['has_previous'],
+        'show_first': 1 not in page_numbers,
+        'show_last': context['pages'] not in page_numbers,
+    }
+
+register.inclusion_tag('telemeta_default/paginator.html', takes_context=True)(paginator)
+
index f5984e51a85bda1438df80a8e5d92f3da03df5e4..b9bceb080c18dd2a56663f176c78a22ec29b3e14 100644 (file)
@@ -291,4 +291,39 @@ def set_var(parser, token):
         raise template.TemplateSyntaxError("'set' tag must be of the form:  {% set <var_name>  = <var_value> %}")
     return SetVarNode(parts[1], parts[3])
  
+def paginator(context, adjacent_pages=2):
+    """
+    To be used in conjunction with the object_list generic view.
+
+    Adds pagination context variables for use in displaying first, adjacent and
+    last page links in addition to those created by the object_list generic
+    view.
+
+    """
+    startPage = max(context['page'] - adjacent_pages, 1)
+    if startPage <= 3: startPage = 1
+    endPage = context['page'] + adjacent_pages + 1
+    if endPage >= context['pages'] - 1: endPage = context['pages'] + 1
+    page_numbers = [n for n in range(startPage, endPage) \
+            if n > 0 and n <= context['pages']]
+    page_obj = context['page_obj']
+    paginator = context['paginator']
+
+    return {
+        'page_obj': page_obj,
+        'paginator': paginator,
+        'hits': context['hits'],
+        'results_per_page': context['results_per_page'],
+        'page': context['page'],
+        'pages': context['pages'],
+        'page_numbers': page_numbers,
+        'next': context['next'],
+        'previous': context['previous'],
+        'has_next': context['has_next'],
+        'has_previous': context['has_previous'],
+        'show_first': 1 not in page_numbers,
+        'show_last': context['pages'] not in page_numbers,
+    }
+
+register.inclusion_tag('paginator.html', takes_context=True)(paginator)