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:
parent
8106e884cb
commit
3ff98a14c0
@ -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()
|
||||
])
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user