Skip to content
This repository was archived by the owner on Apr 17, 2021. It is now read-only.

Commit 081ba15

Browse files
committed
Compatibility with django110
Pass template.render() a dict instead of a context. The autoencoder parameter is now applied by marking the labels as safe html, causing them to render unencoded.
1 parent cb6a543 commit 081ba15

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

bootstrap_pagination/templatetags/bootstrap_pagination.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import re
22

3+
import django
34
from django.core.urlresolvers import reverse, NoReverseMatch
4-
from django.template import Context, Node, Library, TemplateSyntaxError, VariableDoesNotExist
5+
from django.template import Node, Library, TemplateSyntaxError, VariableDoesNotExist
56
from django.template.loader import get_template
67
from django.conf import settings
78
from django.http import QueryDict
9+
from django.utils.html import mark_safe
10+
11+
12+
# As of django 1.10, template rendering no longer accepts a context, but
13+
# instead accepts only accepts a dict. Up until django 1.8, a context was
14+
# actually required. Fortunately Context takes a single dict parameter,
15+
# so for django >=1.9 we can get away with just passing a unit function.
16+
if django.VERSION < (1, 9, 0):
17+
from django.template import Context
18+
else:
19+
Context = lambda x: x
20+
821

922
register = Library()
1023

@@ -68,10 +81,10 @@ def render(self, context):
6881
except VariableDoesNotExist:
6982
kwargs[argname] = None
7083

71-
previous_label = str(kwargs.get("previous_label", "Previous Page"))
72-
next_label = str(kwargs.get("next_label", "Next Page"))
73-
previous_title = str(kwargs.get("previous_title", "Previous Page"))
74-
next_title = str(kwargs.get("next_title", "Next Page"))
84+
previous_label = mark_safe(kwargs.get("previous_label", "Previous Page"))
85+
next_label = mark_safe(kwargs.get("next_label", "Next Page"))
86+
previous_title = mark_safe(kwargs.get("previous_title", "Previous Page"))
87+
next_title = mark_safe(kwargs.get("next_title", "Next Page"))
7588

7689
url_view_name = kwargs.get("url_view_name", None)
7790
if url_view_name is not None:
@@ -100,7 +113,7 @@ def render(self, context):
100113
'next_title': next_title,
101114
'previous_page_url': previous_page_url,
102115
'next_page_url': next_page_url
103-
}, autoescape=False))
116+
}))
104117

105118

106119
class BootstrapPaginationNode(Node):
@@ -136,11 +149,11 @@ def render(self, context):
136149
raise Exception("Optional argument \"size\" expecting one of \"small\", or \"large\"")
137150

138151
show_prev_next = strToBool(kwargs.get("show_prev_next", "true"))
139-
previous_label = str(kwargs.get("previous_label", "&larr;"))
140-
next_label = str(kwargs.get("next_label", "&rarr;"))
152+
previous_label = mark_safe(kwargs.get("previous_label", "&larr;"))
153+
next_label = mark_safe(kwargs.get("next_label", "&rarr;"))
141154
show_first_last = strToBool(kwargs.get("show_first_last", "false"))
142-
first_label = str(kwargs.get("first_label", "&laquo;"))
143-
last_label = str(kwargs.get("last_label", "&raquo;"))
155+
first_label = mark_safe(kwargs.get("first_label", "&laquo;"))
156+
last_label = mark_safe(kwargs.get("last_label", "&raquo;"))
144157
show_index_range = strToBool(kwargs.get("show_index_range", "false"))
145158

146159
url_view_name = kwargs.get("url_view_name", None)
@@ -222,7 +235,7 @@ def render(self, context):
222235
'last_page_url': last_page_url,
223236
'previous_page_url': previous_page_url,
224237
'next_page_url': next_page_url
225-
}, autoescape=False))
238+
}))
226239

227240

228241
@register.tag

0 commit comments

Comments
 (0)