Fixes StreamValue unicode compatibility

pull/2125/merge
Mikalay Radchuk 2016-01-18 23:59:32 +03:00 zatwierdzone przez Matt Westcott
rodzic a2bc7341f2
commit 1e82450160
4 zmienionych plików z 14 dodań i 2 usunięć

Wyświetl plik

@ -36,6 +36,7 @@ Changelog
* Fix: Ordering pages in the explorer by reverse 'last updated' time now puts pages with no revisions at the top
* Fix: WagtailTestUtils now works correctly on custom user models without a ``username`` field (Adam Bolfik)
* Fix: Logging in to the admin as a user with valid credentials but no admin access permission now displays an error message, rather than rejecting the user silently
* Fix: StreamBlock HTML rendering now handles non-ASCII characters correctly on Python 2 (Mikalai Radchuk)
1.3.1 (05.01.2016)
~~~~~~~~~~~~~~~~~~

Wyświetl plik

@ -80,6 +80,7 @@ Bug fixes
* Ordering pages in the explorer by reverse 'last updated' time now puts pages with no revisions at the top
* WagtailTestUtils now works correctly on custom user models without a ``username`` field (Adam Bolfik)
* Logging in to the admin as a user with valid credentials but no admin access permission now displays an error message, rather than rejecting the user silently
* StreamBlock HTML rendering now handles non-ASCII characters correctly on Python 2 (Mikalai Radchuk)
Upgrade considerations

Wyświetl plik

@ -307,7 +307,7 @@ class StreamValue(collections.Sequence):
return repr(list(self))
def __html__(self):
return self.__str__()
return self.stream_block.render(self)
def __str__(self):
return self.stream_block.render(self)
return self.__html__()

Wyświetl plik

@ -1,3 +1,6 @@
# -*- coding: utf-8 -*
from __future__ import unicode_literals
import json
from django.apps import apps
@ -141,12 +144,14 @@ class TestStreamFieldRenderingBase(TestCase):
self.instance = StreamModel.objects.create(body=json.dumps([
{'type': 'rich_text', 'value': '<p>Rich text</p>'},
{'type': 'rich_text', 'value': '<p>Привет, Микола</p>'},
{'type': 'image', 'value': self.image.pk},
{'type': 'text', 'value': 'Hello, World!'}]))
img_tag = self.image.get_rendition('original').img_tag()
self.expected = ''.join([
'<div class="block-rich_text"><div class="rich-text"><p>Rich text</p></div></div>',
'<div class="block-rich_text"><div class="rich-text"><p>Привет, Микола</p></div></div>',
'<div class="block-image">{}</div>'.format(img_tag),
'<div class="block-text">Hello, World!</div>',
])
@ -158,6 +163,11 @@ class TestStreamFieldRendering(TestStreamFieldRenderingBase):
self.assertHTMLEqual(rendered, self.expected)
self.assertIsInstance(rendered, SafeText)
def test___html___access(self):
rendered = self.instance.body.__html__()
self.assertHTMLEqual(rendered, self.expected)
self.assertIsInstance(rendered, SafeText)
class TestStreamFieldDjangoRendering(TestStreamFieldRenderingBase):
def render(self, string, context):