Skip to content

Commit

Permalink
fix ScribbleFormMixin.clean_content for unicode content on Django>1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
imposeren authored and PetrDlouhy committed Jul 29, 2018
1 parent a423d67 commit f50d712
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scribbler/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def clean_content(self):
from django.template import Template
# Try to create a Template
try:
template = Template(template_string=force_text(origin))
template = Template(template_string=force_text(content), origin=origin)
# This is an error with creating the template
except Exception as e:
self.exc_info = {
Expand Down
10 changes: 10 additions & 0 deletions scribbler/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ def test_default_rendering(self):
result = self.render_template_tag(slug='"sidebar"')
self.assertTrue('<p>Default.</p>' in result)

def test_unicode_rendering(self):
"Render with unicode defaults when no scribbles exist."
# On Django>=1.9 ScribbleFormMixin.clean_content directly uses django.template.Template
# and also uses force_text that may fail for non-string objects that have __str__ with
# unicode output.
self.scribble.delete()
unicode_default = '<p>\u0422\u0435\u043a\u0441\u0442.</p>'
result = self.render_template_tag(slug='"sidebar"', default=unicode_default)
self.assertTrue(unicode_default in result)

def test_no_slug_given(self):
"Slug is required by the tag."
self.assertRaises(TemplateSyntaxError, self.render_template_tag, slug='')
Expand Down

0 comments on commit f50d712

Please sign in to comment.