0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

Use correctly sorted StreamBlock children in both prepend and append menus

Previously blocks were only correctly sorted and grouped in the prepend
menu, while they appeared in definition order in the append menu.
This commit is contained in:
Tim Heap 2018-02-19 10:14:36 +02:00 committed by Matt Westcott
parent 18f9736c38
commit e8a9f9d8c9
3 changed files with 10 additions and 3 deletions

View File

@ -9,6 +9,7 @@ Changelog
* Fix: Status button on 'edit page' now links to the correct URL when live and draft slug differ (LB (Ben Johnston))
* Fix: Image title text in the gallery and in the chooser now wraps for long filenames (LB (Ben Johnston), Luiz Boaretto)
* Fix: Move image editor action buttons to the bottom of the form on mobile (Julian Gallo)
* Fix: StreamField icons are now correctly sorted into groups on the 'append' menu (Tim Heap)
2.0 (xx.xx.xxxx) - IN DEVELOPMENT

View File

@ -22,7 +22,8 @@ Bug fixes
* Status button on 'edit page' now links to the correct URL when live and draft slug differ (LB (Ben Johnston))
* Image title text in the gallery and in the chooser now wraps for long filenames (LB (Ben Johnston), Luiz Boaretto)
* Fix: Move image editor action buttons to the bottom of the form on mobile (Julian Gallo)
* Move image editor action buttons to the bottom of the form on mobile (Julian Gallo)
* StreamField icons are now correctly sorted into groups on the 'append' menu (Tim Heap)
Upgrade considerations
======================

View File

@ -56,6 +56,11 @@ class BaseStreamBlock(Block):
"""
return StreamValue(self, self.meta.default)
def sorted_child_blocks(self):
"""Child blocks, sorted in to their groups."""
return sorted(self.child_blocks.values(),
key=lambda child_block: child_block.meta.group)
def render_list_member(self, block_type_name, value, prefix, index, errors=None, id=None):
"""
Render the HTML for a single list item. This consists of an <li> wrapper, hidden fields
@ -64,7 +69,7 @@ class BaseStreamBlock(Block):
child_block = self.child_blocks[block_type_name]
child = child_block.bind(value, prefix="%s-value" % prefix, errors=errors)
return render_to_string('wagtailadmin/block_forms/stream_member.html', {
'child_blocks': self.child_blocks.values(),
'child_blocks': self.sorted_child_blocks(),
'block_type_name': block_type_name,
'prefix': prefix,
'child': child,
@ -138,7 +143,7 @@ class BaseStreamBlock(Block):
return render_to_string('wagtailadmin/block_forms/stream.html', {
'prefix': prefix,
'list_members_html': list_members_html,
'child_blocks': sorted(self.child_blocks.values(), key=lambda child_block: child_block.meta.group),
'child_blocks': self.sorted_child_blocks(),
'header_menu_prefix': '%s-before' % prefix,
'block_errors': error_dict.get(NON_FIELD_ERRORS),
})