from django import template
from django.core.paginator import Paginator, EmptyPage
from django.utils.translation import ugettext as _
+from django.utils.html import escape
from django.http import Http404
+from django.utils.encoding import smart_unicode
from django.utils.http import urlquote
from django.utils.safestring import mark_safe
from django.utils.html import strip_tags, escape
for k, l in querydict.iterlists():
if (not exclude) or (not k in exclude):
- all += ["%s=%s" % (k, urlquote(strip_tags(v))) for v in l]
+ all += ["%s=%s" % (k, escape(strip_tags(v))) for v in l]
return "&".join(all)
return isinstance(self.order_by, (list, tuple)) and self.order_by or [self.order_by]
def apply(self, objects):
- return objects.order_by(*self._get_order_by())
+ if self.order_by:
+ return objects.order_by(*self._get_order_by())
+
+ return objects
class PaginatorContext(object):
visible_page_range = 5
page_numbers = []
if sort:
- url_builder = lambda n: mark_safe("%s%s%s=%s&%s=%s" % (base_path, url_joiner, context.SORT, sort, context.PAGE, n))
+ url_builder = lambda n: mark_safe("%s%s%s=%s&%s=%s" % (escape(base_path), url_joiner, context.SORT, sort, context.PAGE, n))
else:
- url_builder = lambda n: mark_safe("%s%s%s=%s" % (base_path, url_joiner, context.PAGE, n))
+ url_builder = lambda n: mark_safe("%s%s%s=%s" % (escape(base_path), url_joiner, context.PAGE, n))
if range_start > (context.outside_page_range + 1):
page_numbers.append([(n, url_builder(n)) for n in range(1, context.outside_page_range + 1)])
sorts = [(n, s.label, url_builder(n), strip_tags(s.description)) for n, s in context.sort_methods.items()]
for name, label, url, descr in sorts:
- paginator.__dict__['%s_sort_link' % name] = url
+ paginator.__dict__['%s_sort_link' % name] = smart_unicode(url)
return sort_tabs_template.render(template.Context({
'current': sort,