mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-18 12:11:11 +00:00
make StructValue preserve key order from the StructBlock definition
This commit is contained in:
parent
c99bada915
commit
884708cb38
1 changed files with 6 additions and 3 deletions
|
|
@ -388,8 +388,11 @@ class BaseStructBlock(Block):
|
|||
def to_python(self, value):
|
||||
# recursively call to_python on children and return as a StructValue
|
||||
return StructValue(self, [
|
||||
(name, self.child_blocks[name].to_python(val))
|
||||
for name, val in value.items()
|
||||
(
|
||||
name,
|
||||
child_block.to_python(value.get(name, child_block.default))
|
||||
)
|
||||
for name, child_block in self.child_blocks.items()
|
||||
])
|
||||
|
||||
def get_prep_value(self, value):
|
||||
|
|
@ -403,7 +406,7 @@ class BaseStructBlock(Block):
|
|||
return render_to_string(self.template, {'self': value})
|
||||
|
||||
@python_2_unicode_compatible # ensures that the output of __str__ doesn't lose its 'safe' flag
|
||||
class StructValue(dict):
|
||||
class StructValue(collections.OrderedDict):
|
||||
def __init__(self, block, *args):
|
||||
super(StructValue, self).__init__(*args)
|
||||
self.block = block
|
||||
|
|
|
|||
Loading…
Reference in a new issue