|
1 | 1 | import re |
2 | 2 |
|
| 3 | +import django |
3 | 4 | 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 |
5 | 6 | from django.template.loader import get_template |
6 | 7 | from django.conf import settings |
7 | 8 | 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 | + |
8 | 21 |
|
9 | 22 | register = Library() |
10 | 23 |
|
@@ -68,10 +81,10 @@ def render(self, context): |
68 | 81 | except VariableDoesNotExist: |
69 | 82 | kwargs[argname] = None |
70 | 83 |
|
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")) |
75 | 88 |
|
76 | 89 | url_view_name = kwargs.get("url_view_name", None) |
77 | 90 | if url_view_name is not None: |
@@ -100,7 +113,7 @@ def render(self, context): |
100 | 113 | 'next_title': next_title, |
101 | 114 | 'previous_page_url': previous_page_url, |
102 | 115 | 'next_page_url': next_page_url |
103 | | - }, autoescape=False)) |
| 116 | + })) |
104 | 117 |
|
105 | 118 |
|
106 | 119 | class BootstrapPaginationNode(Node): |
@@ -136,11 +149,11 @@ def render(self, context): |
136 | 149 | raise Exception("Optional argument \"size\" expecting one of \"small\", or \"large\"") |
137 | 150 |
|
138 | 151 | show_prev_next = strToBool(kwargs.get("show_prev_next", "true")) |
139 | | - previous_label = str(kwargs.get("previous_label", "←")) |
140 | | - next_label = str(kwargs.get("next_label", "→")) |
| 152 | + previous_label = mark_safe(kwargs.get("previous_label", "←")) |
| 153 | + next_label = mark_safe(kwargs.get("next_label", "→")) |
141 | 154 | show_first_last = strToBool(kwargs.get("show_first_last", "false")) |
142 | | - first_label = str(kwargs.get("first_label", "«")) |
143 | | - last_label = str(kwargs.get("last_label", "»")) |
| 155 | + first_label = mark_safe(kwargs.get("first_label", "«")) |
| 156 | + last_label = mark_safe(kwargs.get("last_label", "»")) |
144 | 157 | show_index_range = strToBool(kwargs.get("show_index_range", "false")) |
145 | 158 |
|
146 | 159 | url_view_name = kwargs.get("url_view_name", None) |
@@ -222,7 +235,7 @@ def render(self, context): |
222 | 235 | 'last_page_url': last_page_url, |
223 | 236 | 'previous_page_url': previous_page_url, |
224 | 237 | 'next_page_url': next_page_url |
225 | | - }, autoescape=False)) |
| 238 | + })) |
226 | 239 |
|
227 | 240 |
|
228 | 241 | @register.tag |
|
0 commit comments