Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widget_from_block returns unknown type for ImageChooser/DocumentChooser inside a ListBlock #638

Closed
tspnn opened this issue Oct 17, 2022 · 1 comment
Labels
type:bug Something isn't working

Comments

@tspnn
Copy link
Contributor

tspnn commented Oct 17, 2022

When a ListBlock contains an ImageChooserBlock or a DocumentChooserBlock, function widget_from_block returns {"type": "unknown"} because content_components is None

Model:

class HomePage(Page):
    body = StreamField(
        [
            ("text", blocks.TextBlock()),
            ("images", blocks.ListBlock(ImageChooserBlock())),
            ("documents", blocks.ListBlock(DocumentChooserBlock())),
        ],
        blank=True,
        null=True,
        use_json_field=True,
    )

    content_panels = Page.content_panels + [
        FieldPanel("body"),
    ]
  • python 3.9.5
  • django 4.1.2
  • wagtail 4.0.2
  • wagtail-localize 1.3

Wagtail Admin

Possible solution:
Add an extra elif statement that checks if the block is an instance of a ListBlock and content_components is None:

if isinstance(block, blocks.PageChooserBlock):
    ...
elif isinstance(block, blocks.ListBlock) and content_components is not None:
    return widget_from_block(block.child_block, content_components[1:])
# add this
elif isinstance(block, blocks.ListBlock) and content_components is None:
    return widget_from_block(block.child_block)
@zerolab
Copy link
Collaborator

zerolab commented Oct 17, 2022

I would've thought we had this covered by tests. Suppose not.

Will try to make a new patch release in the next 2-3 days. Or happily review a PR

@zerolab zerolab added the type:bug Something isn't working label Oct 17, 2022
@tspnn tspnn closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants