From 342fd7a06187d034a151db542f42a47b8ad71a13 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Mon, 16 Feb 2015 12:17:56 +0000 Subject: [PATCH] make block names work properly when passed as binary strings --- wagtail/wagtailcore/blocks.py | 2 +- wagtail/wagtailcore/tests/test_blocks.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailcore/blocks.py b/wagtail/wagtailcore/blocks.py index 30b19e72f..8d45a9df2 100644 --- a/wagtail/wagtailcore/blocks.py +++ b/wagtail/wagtailcore/blocks.py @@ -115,7 +115,7 @@ class Block(six.with_metaclass(BaseBlock, object)): def set_name(self, name): self.name = name if not self.meta.label: - self.label = capfirst(name.replace('_', ' ')) + self.label = capfirst(force_text(name).replace('_', ' ')) @property def media(self): diff --git a/wagtail/wagtailcore/tests/test_blocks.py b/wagtail/wagtailcore/tests/test_blocks.py index 282c879ef..6d9fd0115 100644 --- a/wagtail/wagtailcore/tests/test_blocks.py +++ b/wagtail/wagtailcore/tests/test_blocks.py @@ -408,6 +408,15 @@ class TestStreamBlock(unittest.TestCase): self.assertEqual(list(block.child_blocks.keys()), ['heading', 'paragraph']) + def test_initialisation_with_binary_string_names(self): + # migrations will sometimes write out names as binary strings, just to keep us on our toes + block = blocks.StreamBlock([ + (b'heading', blocks.CharBlock()), + (b'paragraph', blocks.CharBlock()), + ]) + + self.assertEqual(list(block.child_blocks.keys()), [b'heading', b'paragraph']) + def test_initialisation_from_subclass(self): class ArticleBlock(blocks.StreamBlock): heading = blocks.CharBlock()