paging maintains other GET parameters -- contributed by jezdez
authorjtauber <jtauber@7f1efe38-554e-0410-b69d-834cb44da2d5>
Wed, 18 Jun 2008 09:48:32 +0000 (09:48 +0000)
committerjtauber <jtauber@7f1efe38-554e-0410-b69d-834cb44da2d5>
Wed, 18 Jun 2008 09:48:32 +0000 (09:48 +0000)
git-svn-id: https://django-pagination.googlecode.com/svn/trunk@14 7f1efe38-554e-0410-b69d-834cb44da2d5

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

index 8abee2d..3799314 100644 (file)
@@ -1,8 +1,25 @@
 {% if is_paginated %}
 <div class="pagination">
 {% if is_paginated %}
 <div class="pagination">
-    {% if page_obj.has_previous %}<a href="?page={{ page_obj.previous_page_number }}" class="prev">&lsaquo;&lsaquo; previous</a> {% else %}<span class="disabled prev">&lsaquo;&lsaquo; 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 }}" class="page">{{ page }}</a> {% endifequal %}{% else %} ... {% endif %}
+    {% if page_obj.has_previous %}
+        <a href="?page={{ page_obj.previous_page_number }}{{ getvars }}" class="prev">&lsaquo;&lsaquo; previous</a>
+    {% else %}
+        <span class="disabled prev">&lsaquo;&lsaquo; 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 }}{{ getvars }}" class="page">{{ page }}</a>
+            {% endifequal %}
+        {% else %}
+            ...
+        {% endif %}
     {% endfor %}
     {% endfor %}
-    {% if page_obj.has_next %}<a href="?page={{ page_obj.next_page_number }}" class="next">next &rsaquo;&rsaquo;</a>{% else %}<span class="disabled next">next &rsaquo;&rsaquo;</span>{% endif %}
+    {% if page_obj.has_next %}
+        <a href="?page={{ page_obj.next_page_number }}{{ getvars }}" class="next">next &rsaquo;&rsaquo;</a>
+    {% else %}
+        <span class="disabled next">next &rsaquo;&rsaquo;</span>
+    {% endif %}
 </div>
 </div>
-{% endif %}
\ No newline at end of file
+{% endif %}
index e688b05..6db06ba 100644 (file)
@@ -114,11 +114,16 @@ def paginate(context, window=4):
             pages.extend(second_list)
         else:
             pages.extend(sorted(list(last.difference(current))))
             pages.extend(second_list)
         else:
             pages.extend(sorted(list(last.difference(current))))
-        return { 
+        
+        getvars = context['request'].GET.copy()
+        if 'page' in getvars:
+            del getvars['page']
+        return {
             'pages': pages,
             'page_obj': page_obj,
             'paginator': paginator,
             'is_paginated': paginator.count > paginator.per_page,
             'pages': pages,
             'page_obj': page_obj,
             'paginator': paginator,
             'is_paginated': paginator.count > paginator.per_page,
+            'getvars': "&%s" % getvars.urlencode()
         }
     except KeyError:
         return u''
         }
     except KeyError:
         return u''