Commits

offline  committed 7b58246

uri params are encoded by unicode aware urlencode function

  • Participants
  • Parent commits b8fa6a6

Comments (0)

Files changed (2)

File ninjapaginator/templates/paginator.html

     {% ifequal i page_num %}
         <span class="digg_pages_disabled">{{ i }}</span>
     {% else %}
-        <a class="digg_pages" href='?page={{ i }}'>{{ i }}</a>
+        <a class="digg_pages" href='?page={{ i }}&{{ extra_params }}'>{{ i }}</a>
     {% endifequal %}
 {% endfor %}
 {% endif %}
     {% ifequal i page_num %}
         <span class="digg_pages_disabled">{{ i }}</span>
     {% else %}
-        <a class="digg_pages" href='?page={{ i }}'>{{ i }}</a>
+        <a class="digg_pages" href='?page={{ i }}&{{ extra_params }}'>{{ i }}</a>
     {% endifequal %}
 {% endfor %}
 {% endif %}
     {% ifequal i page_num %}
         <span class="digg_pages_disabled">{{ i }}</span>
     {% else %}
-        <a class="digg_pages" href='?page={{ i }}'>{{ i }}</a>
+        <a class="digg_pages" href='?page={{ i }}&{{ extra_params }}'>{{ i }}</a>
     {% endifequal %}
 {% endfor %}
 {% endif %}
 
 {% if NEXT %}
-    <a href='?page={{ NEXT }}' class="digg_nextprev">Next &gt;&gt;</a>
+    <a href='?page={{ NEXT }}&{{ extra_params }}' class="digg_nextprev">Next &gt;&gt;</a>
 {% else %}
     <span class="digg_nextprev_disabled">Next &gt;&gt;</span>
 {% endif %}
     {% ifequal i page_num %}
         <span class="filmfeed_pages_disabled">{{ i }}</span>
     {% else %}
-        <a href='?page={{ i }}' class="filmfeed_pages">{{ i }}</a>
+        <a href='?page={{ i }}&{{ extra_params }}' class="filmfeed_pages">{{ i }}</a>
     {% endifequal %}
 {% endfor %}
 {% endif %}

File ninjapaginator/util.py

 # -*- coding: utf-8 -*-
 
+from urllib import urlencode
+
 from django.utils.datastructures import MultiValueDictKeyError
 from django.core.paginator import Paginator, EmptyPage
 from django.http import Http404
+from django.conf import settings
 
 
+def unicode_urlencode(params):
+    """
+    A unicode aware version of urllib.urlencode
+    """
+
+    if isinstance(params, dict):
+        params = params.items()
+    return urlencode([(k, isinstance(v, unicode) and v.encode('utf-8') or v) for k, v in params])
+
 
 class NinjaPaginator(object):
     """
     http://bitbucket.org/offline/django-annoying/wiki/Home
     """
 
-    def __init__(self, object_list='object_list', style='digg', per_page=10, frame_size=8):
+    def __init__(self, object_list='object_list', style=None, per_page=10, frame_size=8):
         """
         receive decorator parameters 
         """
         self.object_list = object_list
-        self.style = style
+        self.style = style or getattr(settings, "PAGINATION_STYLE", "digg")
         self.per_page = per_page
         self.per_page_backup = per_page
         self.frame_size = frame_size
             self.per_page = self.per_page_backup
             params['per_page'] = self.per_page
             
-        extra_params = ""
-
-        for k,v in params.items():
-            extra_params += "&%s=%s" % (k, v)
+        extra_params = unicode_urlencode(params)
 
         self.paginate_qs = self.output.pop(self.object_list)
         self.paginator = Paginator(self.paginate_qs, self.per_page)