0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

StructBlock.value_from_datadict should return a StructValue, not dict - fixes #1100

This commit is contained in:
Matt Westcott 2015-03-25 11:47:27 +00:00
parent 8106e884cb
commit 3ff98a14c0
2 changed files with 18 additions and 1 deletions

View File

@ -80,7 +80,7 @@ class BaseStructBlock(Block):
return format_html('<div class="struct-block"><ul>{0}</ul></div>', list_items)
def value_from_datadict(self, data, files, prefix):
return dict([
return StructValue(self, [
(name, block.value_from_datadict(data, files, '%s-%s' % (prefix, name)))
for name, block in self.child_blocks.items()
])

View File

@ -438,6 +438,23 @@ class TestStructBlock(unittest.TestCase):
self.assertEqual(content, ["Wagtail site"])
def test_value_from_datadict(self):
block = blocks.StructBlock([
('title', blocks.CharBlock()),
('link', blocks.URLBlock()),
])
struct_val = block.value_from_datadict({
'mylink-title': "Torchbox",
'mylink-link': "http://www.torchbox.com"
}, {}, 'mylink')
self.assertEqual(struct_val['title'], "Torchbox")
self.assertEqual(struct_val['link'], "http://www.torchbox.com")
self.assertTrue(isinstance(struct_val, blocks.StructValue))
self.assertTrue(isinstance(struct_val.bound_blocks['link'].block, blocks.URLBlock))
class TestListBlock(unittest.TestCase):
def test_initialise_with_class(self):