Skip to content

Commit 3990538

Browse files
committed
Fix django 1.4 compatibility.
1 parent d362c94 commit 3990538

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

fileupload/templates/fileupload/picture_angular_form.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load verbatim_tag %}
12
<!DOCTYPE HTML>
23
<!--
34
/*

fileupload/templates/fileupload/picture_jquery_form.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% load verbatim_tag %}
12
<!DOCTYPE HTML>
23
<!--
34
/*
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
jQuery templates use constructs like:
3+
4+
{{if condition}} print something{{/if}}
5+
6+
This, of course, completely screws up Django templates,
7+
because Django thinks {{ and }} mean something.
8+
9+
Wrap {% verbatim %} and {% endverbatim %} around those
10+
blocks of jQuery templates and this will try its best
11+
to output the contents with no changes.
12+
"""
13+
14+
from django import template
15+
16+
register = template.Library()
17+
18+
19+
class VerbatimNode(template.Node):
20+
21+
def __init__(self, text):
22+
self.text = text
23+
24+
def render(self, context):
25+
return self.text
26+
27+
28+
@register.tag
29+
def verbatim(parser, token):
30+
text = []
31+
while 1:
32+
token = parser.tokens.pop(0)
33+
if token.contents == 'endverbatim':
34+
break
35+
if token.token_type == template.TOKEN_VAR:
36+
text.append('{{')
37+
elif token.token_type == template.TOKEN_BLOCK:
38+
text.append('{%')
39+
text.append(token.contents)
40+
if token.token_type == template.TOKEN_VAR:
41+
text.append('}}')
42+
elif token.token_type == template.TOKEN_BLOCK:
43+
text.append('%}')
44+
return VerbatimNode(''.join(text))

0 commit comments

Comments
 (0)