Merge branch 'master' of git://github.com/cicuz/django-pagination
authorZygmunt Krynicki <zygmunt.krynicki@linaro.org>
Mon, 13 Jun 2011 12:30:21 +0000 (14:30 +0200)
committerZygmunt Bazyli Krynicki <Zygmunt Krynicki zygmunt.krynicki@linaro.org>
Mon, 13 Jun 2011 12:30:21 +0000 (14:30 +0200)
Conflicts:
linaro_django_pagination/templates/pagination/pagination.html
linaro_django_pagination/templatetags/pagination_tags.py

.gitignore
MANIFEST.in
docs/usage.txt
linaro_django_pagination/locale/it/LC_MESSAGES/django.po [new file with mode: 0644]
linaro_django_pagination/templates/pagination/default.html [new file with mode: 0644]
linaro_django_pagination/templates/pagination/pagination.html
linaro_django_pagination/templatetags/pagination_tags.py [changed mode: 0644->0755]
linaro_django_pagination/tests.py

index d7c2b72..7db9a19 100644 (file)
@@ -1,3 +1,4 @@
+*.egg-info
 *.pyc
+build
 dist
-*.egg-info
index 74bebc4..471e508 100644 (file)
@@ -1,4 +1,5 @@
 include LICENSE.txt
 include CONTRIBUTORS.txt
 recursive-include docs *
-recursive-include pagination/templates/pagination *.html
\ No newline at end of file
+recursive-include pagination/templates/pagination *.html
+recursive-include pagination/locale *
\ No newline at end of file
index bb819b5..756787d 100644 (file)
@@ -69,6 +69,19 @@ installation, which is covered in INSTALL.txt in this same directory.)
 That's it!  You have now paginated ``object_list`` and given users of the site
 a way to navigate between the different pages--all without touching your views.
 
+Custom pagination templates
+---------------------------
+
+In order to override the default pagination template, declare a context variable 
+named ``pagination_template`` set to the template name::
+
+    {% with 'pagination/blog/post.html' as pagination_template %}
+        {% autopaginate posts pagesize %}
+        {% paginate %}
+    {% endwith %}
+
+The default pagination template is contained in the ``pagination/default.html`` 
+file inside the distribution.
 
 A Note About Uploads
 --------------------
@@ -103,4 +116,21 @@ pagination tags.  Here's an overview:
 ``PAGINATION_INVALID_PAGE_RAISES_404``
     Determines whether an invalid page raises an ``Http404`` or just sets the
     ``invalid_page`` context variable.  ``True`` does the former and ``False``
-    does the latter.
\ No newline at end of file
+    does the latter.
+
+``DISPLAY_PAGE_LINKS``
+    If set to ``False``, links for single pages will not be displayed.
+
+``PREVIOUS_LINK_DECORATOR``
+    An HTML prefix for the previous page link; the default value is ``&lsaquo;&lsaquo; ``.
+
+``NEXT_LINK_DECORATOR``
+    An HTML postfix for the next page link; the default value is `` &rsaquo;&rsaquo;``.
+
+``DISPLAY_DISABLED_PREVIOUS_LINK``
+    If set to ``False``, the previous page link will not be displayed if there's 
+    no previous page.
+
+``DISPLAY_DISABLED_NEXT_LINK``
+    If set to ``False``, the next page link will not be displayed if there's no 
+    next page.
diff --git a/linaro_django_pagination/locale/it/LC_MESSAGES/django.po b/linaro_django_pagination/locale/it/LC_MESSAGES/django.po
new file mode 100644 (file)
index 0000000..a8832db
--- /dev/null
@@ -0,0 +1,24 @@
+# django-pagination Italian translation
+# Copyright (C) 2010 Fabio Corneti <info@corneti.com>
+# This file is distributed under the same license as the django-pagination package.
+# Fabio Corneti <info@corneti.com>, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-04-22 12:04+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: templates/pagination/default.html:6 templates/pagination/default.html:9
+msgid "previous"
+msgstr "precedenti"
+
+#: templates/pagination/default.html:30 templates/pagination/default.html:33
+msgid "next"
+msgstr "successive"
diff --git a/linaro_django_pagination/templates/pagination/default.html b/linaro_django_pagination/templates/pagination/default.html
new file mode 100644 (file)
index 0000000..1bd9ab5
--- /dev/null
@@ -0,0 +1,38 @@
+{% if is_paginated %}
+{% load i18n %}
+<div class="pagination">
+  {% block previouslink %}
+  {% if page_obj.has_previous %}
+  <a href="?page{{ page_suffix }}={{ page_obj.previous_page_number }}{{ getvars }}" class="prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</a>
+  {% else %}
+  {% if display_disabled_previous_link %}
+  <span class="disabled prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</span>
+  {% endif %}
+  {% endif %}
+  {% endblock previouslink %}
+  {% block pagelinks %}
+  {% 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_suffix }}={{ page }}{{ getvars }}" class="page">{{ page }}</a>
+  {% endifequal %}
+  {% else %}
+  ...
+  {% endif %}
+  {% endfor %}
+  {% endif %}
+  {% endblock pagelinks %}
+  {% block nextlink %}
+  {% if page_obj.has_next %}
+  <a href="?page{{ page_suffix }}={{ page_obj.next_page_number }}{{ getvars }}" class="next">{% trans "next" %}{{ next_link_decorator|safe }}</a>
+  {% else %}
+  {% if display_disabled_next_link %}
+  <span class="disabled next">{% trans "next" %}{{ next_link_decorator|safe }}</span>
+  {% endif %}
+  {% endif %}
+  {% endblock nextlink %}
+</div>
+{% endif %}
index c2fb72d..fd925f0 100644 (file)
@@ -1,26 +1 @@
-{% if is_paginated %}
-{% load i18n %}
-<div class="pagination">
-    {% if page_obj.has_previous %}
-        <a href="?page{{ page_suffix }}={{ page_obj.previous_page_number }}{{ getvars }}" class="prev">&lsaquo;&lsaquo; {% trans "previous" %}</a>
-    {% else %}
-        <span class="disabled prev">&lsaquo;&lsaquo; {% trans "previous" %}</span>
-    {% endif %}
-    {% for page in pages %}
-        {% if page %}
-            {% ifequal page page_obj.number %}
-                <span class="current page">{{ page }}</span>
-            {% else %}
-                <a href="?page{{ page_suffix }}={{ page }}{{ getvars }}" class="page">{{ page }}</a>
-            {% endifequal %}
-        {% else %}
-            ...
-        {% endif %}
-    {% endfor %}
-    {% if page_obj.has_next %}
-        <a href="?page{{ page_suffix }}={{ page_obj.next_page_number }}{{ getvars }}" class="next">{% trans "next" %} &rsaquo;&rsaquo;</a>
-    {% else %}
-        <span class="disabled next">{% trans "next" %} &rsaquo;&rsaquo;</span>
-    {% endif %}
-</div>
-{% endif %}
+{% include pagination_template %}
old mode 100644 (file)
new mode 100755 (executable)
index 75cbcf3..af1be0f
@@ -16,6 +16,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', False)
+DISPLAY_DISABLED_NEXT_LINK = getattr(settings, 'PAGINATION_DISPLAY_DISABLED_NEXT_LINK', False)
 
 def do_autopaginate(parser, token):
     """
@@ -163,12 +168,23 @@ def paginate(context, window=DEFAULT_WINDOW):
         A dictionary of all of the **GET** parameters in the current request.
         This is useful to maintain certain types of state, even when requesting
         a different page.
-        """
+    
+    ``pagination_template``
+        A custom template to include in place of the default ``pagination.html`` 
+        contents.
+        
+    """
     try:
         paginator = context['paginator']
         page_obj = context['page_obj']
         page_suffix = context.get('page_suffix', '')
         page_range = paginator.page_range
+        pagination_template = context.get('pagination_template', 'pagination/default.html')
+        # Calculate the record range in the current page for display.
+        records = {'first': 1 + (page_obj.number - 1) * paginator.per_page}
+        records['last'] = records['first'] + paginator.per_page - 1
+        if records['last'] + paginator.orphans >= paginator.count:
+            records['last'] = paginator.count
         # First and last are simply the first *n* pages and the last *n* pages,
         # where *n* is the current window size.
         first = set(page_range[:window])
@@ -240,6 +256,12 @@ def paginate(context, window=DEFAULT_WINDOW):
             'paginator': paginator,
             'is_paginated': paginator.count > paginator.per_page,
             'page_suffix': page_suffix,
+            '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,
+            'pagination_template': pagination_template,
         }
         if 'request' in context:
             getvars = context['request'].GET.copy()
index 267b77d..d31c4ed 100644 (file)
 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
 [1, 2, 3, 4, None, 7, 8, 9, 10]
 
+>>> p = Paginator(range(21), 2, 1)
+>>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
+[1, 2, 3, 4, None, 7, 8, 9, 10]
+
 >>> t = Template("{% load pagination_tags %}{% autopaginate var 2 %}{% paginate %}")
 
 >>> from django.http import HttpRequest as DjangoHttpRequest