]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/utils/pagination.py
fixes OSQA-439. IE should work again. Sorry about that. Thanks for the patches...
[osqa.git] / forum / utils / pagination.py
index ca7c2728b51f4f8e641ca8f9ecdbb6b6b149db9b..c36ad2fb35cacc104597306d8ed4d20c2c52d50d 100644 (file)
@@ -4,11 +4,21 @@ from django import template
 from django.core.paginator import Paginator, EmptyPage
 from django.utils.translation import ugettext as _
 from django.http import Http404
+from django.utils.http import urlquote
 from django.utils.safestring import mark_safe
 from django.utils.html import strip_tags
 
 import logging
 
+def generate_uri(querydict, exclude=None):
+    all = []
+
+    for k, l in querydict.iterlists():
+        if (not exclude) or (not k in exclude):
+            all += ["%s=%s" % (k, urlquote(v)) for v in l]
+        
+    return "&".join(all)
+
 class SortBase(object):
     def __init__(self, label, description=''):
         self.label = label
@@ -107,7 +117,7 @@ class PaginatorContext(object):
 
     def page(self, request):
         try:
-            return int(request.GET.get(self.PAGE, 1))
+            return int(request.GET.get(self.PAGE, "1").strip())
         except ValueError:
             logging.error('Found invalid page number "%s", loading %s, refered by %s' % (
                 request.GET.get(self.PAGE, ''), request.path, request.META.get('HTTP_REFERER', 'UNKNOWN')
@@ -189,10 +199,10 @@ def _paginated(request, objects, context):
         base_path = context.base_path
     else:
         base_path = request.path
-        get_params = ["%s=%s" % (k, v) for k, v in request.GET.items() if not k in (context.PAGE, context.PAGESIZE, context.SORT)]
+        get_params = generate_uri(request.GET, (context.PAGE, context.PAGESIZE, context.SORT))
 
         if get_params:
-            base_path += "?" + "&".join(get_params)
+            base_path += "?" + get_params
 
     url_joiner = "?" in base_path and "&" or "?"