New settings for basic pagination customization, backwards compatible:
authorFabio Corneti <info@corneti.com>
Thu, 22 Apr 2010 08:56:17 +0000 (10:56 +0200)
committerFabio Corneti <info@corneti.com>
Thu, 22 Apr 2010 08:56:17 +0000 (10:56 +0200)
* DISPLAY_PAGE_LINKS
* PREVIOUS_LINK_DECORATOR
* NEXT_LINK_DECORATOR
* DISPLAY_DISABLED_PREVIOUS_LINK
* DISPLAY_DISABLED_NEXT_LINK

pagination/templates/pagination/pagination.html
pagination/templatetags/pagination_tags.py

index fe566a8..8dd3679 100644 (file)
@@ -2,25 +2,31 @@
 {% load i18n %}
 <div class="pagination">
     {% if page_obj.has_previous %}
-        <a href="?page={{ page_obj.previous_page_number }}{{ getvars }}{{ hashtag }}" class="prev">&lsaquo;&lsaquo; {% trans "previous" %}</a>
+        <a href="?page={{ page_obj.previous_page_number }}{{ getvars }}{{ hashtag }}" class="prev">{{ previous_link_decorator }}{% trans "previous" %}</a>
     {% else %}
-        <span class="disabled prev">&lsaquo;&lsaquo; {% trans "previous" %}</span>
+        {% if display_disabled_previous_link %}
+            <span class="disabled prev">{{ previous_link_decorator }}{% trans "previous" %}</span>    
+        {% endif %}
     {% endif %}
-    {% for page in pages %}
-        {% if page %}
-            {% ifequal page page_obj.number %}
-                <span class="current page">{{ page }}</span>
+    {% if display_page_links %}
+        {% for page in pages %}
+            {% if page %}
+                {% ifequal page page_obj.number %}
+                    <span class="current page">{{ page }}</span>
+                {% else %}
+                    <a href="?page={{ page }}{{ getvars }}{{ hashtag }}" class="page">{{ page }}</a>
+                {% endifequal %}
             {% else %}
-                <a href="?page={{ page }}{{ getvars }}{{ hashtag }}" class="page">{{ page }}</a>
-            {% endifequal %}
-        {% else %}
-            ...
-        {% endif %}
-    {% endfor %}
+                ...
+            {% endif %}
+        {% endfor %}        
+    {% endif %}
     {% if page_obj.has_next %}
-        <a href="?page={{ page_obj.next_page_number }}{{ getvars }}{{ hashtag }}" class="next">{% trans "next" %} &rsaquo;&rsaquo;</a>
+        <a href="?page={{ page_obj.next_page_number }}{{ getvars }}{{ hashtag }}" class="next">{% trans "next" %}{{ next_link_decorator }}</a>
     {% else %}
-        <span class="disabled next">{% trans "next" %} &rsaquo;&rsaquo;</span>
+        {% if display_disabled_next_link %}
+            <span class="disabled next">{% trans "next" %}{{ next_link_decorator }}</span>
+        {% endif %}
     {% endif %}
 </div>
-{% endif %}
+{% endif %}
\ No newline at end of file
index ae843b1..f7de347 100644 (file)
@@ -15,6 +15,11 @@ DEFAULT_WINDOW = getattr(settings, 'PAGINATION_DEFAULT_WINDOW', 4)
 DEFAULT_ORPHANS = getattr(settings, 'PAGINATION_DEFAULT_ORPHANS', 0)
 INVALID_PAGE_RAISES_404 = getattr(settings,
     'PAGINATION_INVALID_PAGE_RAISES_404', False)
+DISPLAY_PAGE_LINKS = getattr(settings, 'PAGINATION_DISPLAY_PAGE_LINKS', True)
+PREVIOUS_LINK_DECORATOR = getattr(settings, 'PAGINATION_PREVIOUS_LINK_DECORATOR', "&lsaquo;&lsaquo; ")
+NEXT_LINK_DECORATOR = getattr(settings, 'PAGINATION_NEXT_LINK_DECORATOR', " &rsaquo;&rsaquo;")
+DISPLAY_DISABLED_PREVIOUS_LINK = getattr(settings, 'PAGINATION_DISPLAY_DISABLED_PREVIOUS_LINK', True)
+DISPLAY_DISABLED_NEXT_LINK = getattr(settings, 'PAGINATION_DISPLAY_DISABLED_NEXT_LINK', True)
 
 def do_autopaginate(parser, token):
     """
@@ -212,6 +217,11 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''):
             'paginator': paginator,
             'hashtag': hashtag,
             'is_paginated': paginator.count > paginator.per_page,
+            'display_page_links': DISPLAY_PAGE_LINKS,
+            'display_disabled_previous_link': DISPLAY_DISABLED_PREVIOUS_LINK,
+            'display_disabled_next_link': DISPLAY_DISABLED_NEXT_LINK,
+            'previous_link_decorator': PREVIOUS_LINK_DECORATOR,
+            'next_link_decorator': NEXT_LINK_DECORATOR,
         }
         if 'request' in context:
             getvars = context['request'].GET.copy()