within StreamBlock's default rendering, call force_text on children to prevent spurious escaping - fixes #1078

This commit is contained in:
Matt Westcott 2015-03-20 20:58:52 +00:00
parent 7fdf7bb10c
commit 156f715be6
2 changed files with 7 additions and 7 deletions

View file

@ -6,7 +6,7 @@ from django import forms
from django.core.exceptions import ValidationError
from django.forms.utils import ErrorList
from django.template.loader import render_to_string
from django.utils.encoding import python_2_unicode_compatible
from django.utils.encoding import python_2_unicode_compatible, force_text
from django.utils.html import format_html_join
from django.utils.safestring import mark_safe
@ -192,7 +192,7 @@ class BaseStreamBlock(Block):
def render_basic(self, value):
return format_html_join('\n', '<div class="block-{1}">{0}</div>',
[(child, child.block_type) for child in value]
[(force_text(child), child.block_type) for child in value]
)
def get_searchable_content(self, value):

View file

@ -663,7 +663,7 @@ class TestStreamBlock(unittest.TestCase):
def render_article(self, data):
class ArticleBlock(blocks.StreamBlock):
heading = blocks.CharBlock()
paragraph = blocks.CharBlock()
paragraph = blocks.RichTextBlock()
block = ArticleBlock()
value = block.to_python(data)
@ -678,7 +678,7 @@ class TestStreamBlock(unittest.TestCase):
},
{
'type': 'paragraph',
'value': 'My first paragraph',
'value': 'My <i>first</i> paragraph',
},
{
'type': 'paragraph',
@ -687,8 +687,8 @@ class TestStreamBlock(unittest.TestCase):
])
self.assertIn('<div class="block-heading">My title</div>', html)
self.assertIn('<div class="block-paragraph">My first paragraph</div>', html)
self.assertIn('<div class="block-paragraph">My second paragraph</div>', html)
self.assertIn('<div class="block-paragraph"><div class="rich-text">My <i>first</i> paragraph</div></div>', html)
self.assertIn('<div class="block-paragraph"><div class="rich-text">My second paragraph</div></div>', html)
def test_render_unknown_type(self):
# This can happen if a developer removes a type from their StreamBlock
@ -704,7 +704,7 @@ class TestStreamBlock(unittest.TestCase):
])
self.assertNotIn('foo', html)
self.assertNotIn('Hello', html)
self.assertIn('<div class="block-paragraph">My first paragraph</div>', html)
self.assertIn('<div class="block-paragraph"><div class="rich-text">My first paragraph</div></div>', html)
def render_form(self):
class ArticleBlock(blocks.StreamBlock):