From 389ba8fa7087e2dfa3eb5163f822704bf1bc39d8 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Wed, 12 Oct 2022 20:56:12 +0100 Subject: [PATCH] Fix widget extraction for chooser in `StructBlock`/`StreamBlock` in `ListBlock` --- wagtail_localize/views/edit_translation.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wagtail_localize/views/edit_translation.py b/wagtail_localize/views/edit_translation.py index 47af3d32f..4a562c309 100644 --- a/wagtail_localize/views/edit_translation.py +++ b/wagtail_localize/views/edit_translation.py @@ -500,7 +500,7 @@ def widget_from_block(block, content_components=None): return widget_from_block( block.child_blocks.get(block_field_name), content_components ) - elif isinstance(block, blocks.ListBlock): + elif isinstance(block, blocks.ListBlock) and content_components is not None: return widget_from_block(block.child_block, content_components[1:]) return {"type": "unknown"} @@ -513,6 +513,17 @@ def widget_from_block(block, content_components=None): block_field_name = field_path_components[2] block_field = block_type.child_blocks[block_field_name].label content_components = field_path_components[2:] + elif isinstance(block_type, blocks.ListBlock): + block_field = None + content_components = None + if isinstance( + block_type.child_block, (blocks.StructBlock, blocks.StreamBlock) + ): + block_field_name = field_path_components[3] + block_field = block_type.child_block.child_blocks[ + block_field_name + ].label + content_components = field_path_components[2:] else: block_field = None content_components = None