Skip to content

Commit

Permalink
python2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Gagaro committed Jan 6, 2018
1 parent 020c726 commit 20fd5dd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions wagtail_calendar/templatetags/wagtail_calendar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
register = template.Library()


_json_tag_escapes = {
ord('>'): '\\u003E',
ord('<'): '\\u003C',
ord('&'): '\\u0026',
JSON_TAG_ESCAPES = {
'>': '\\u003E',
'<': '\\u003C',
'&': '\\u0026',
'"': '&quot;',
}


@register.filter(name='json', is_safe=True)
def json_filter(value):
return mark_safe(json.dumps(value, cls=DjangoJSONEncoder).translate(_json_tag_escapes).replace('"', '&quot;'))
text = json.dumps(value, cls=DjangoJSONEncoder)
for char, to in JSON_TAG_ESCAPES.items():
text.replace(char, to)
return mark_safe(text)

0 comments on commit 20fd5dd

Please sign in to comment.