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

Wagtail 2.13 compatibility #14

Merged
merged 6 commits into from
May 16, 2021
Merged

Conversation

gasman
Copy link
Contributor

@gasman gasman commented May 7, 2021

Fixes #11. The new telepath StreamField implementation in 2.13 requires some fairly heavy refactoring to the InstanceSelector widget, since InstanceSelector was quite heavily reliant on rendering a template for each instance, while StreamField needs to be able to construct them client-side from serialised data. I got it working by extracting an 'state' dict consisting of the pk, display_markup and edit_url, which can be used by both the server-side and client-side rendering logic.

(For reference, I submitted a fairly similar patch to wagtailmodelchooser that might help in following the changes: neon-jungle/wagtailmodelchooser#27)

gasman added 6 commits May 7, 2021 12:39
Rendered widget output is now embedded in JSON within the data-block attribute, rather than directly on the page, and needs to be escaped accordingly
This provides a way for the data required to render the widget to be serialised and passed to Javascript, so it can be rendered and populated client-side and not just through a Django template.
This is built-in functionality of the WidgetWithScript utility class used by AdminChooser, and saves us having to include the initialisation JS in the template. Doing it this way means that we can call render_html from the StreamField logic to get just the HTML without the JS (and then trigger the JS at the right point in the StreamField lifecycle).
The standard widget rendering does not use this, as the call to create_instance_selector_widget ignores the return value. However, it will be used by the client-side component in the telepath implementation of StreamField: https://docs.wagtail.io/en/latest/reference/streamfield/widget_api.html
@gasman
Copy link
Contributor Author

gasman commented May 7, 2021

Just to add - wagtail-instance-selector's modal embeds are affected by wagtail/wagtail#7169, so if you test against the current 2.13 release candidates you may encounter JS errors on opening them... this will be fixed for 2.13 final.

@zerolab
Copy link

zerolab commented May 12, 2021

@markfinger Wagtail 2.13 is now out - https://github.com/wagtail/wagtail/releases/tag/v2.13 - would be great to have this reviewed and released out in the wild, if you have time.

@mixxorz
Copy link

mixxorz commented May 12, 2021

This looks amazing! Thanks @gasman!

@markfinger markfinger merged commit a7e553d into ixc:master May 16, 2021
@markfinger
Copy link
Collaborator

Thanks for all the work, @gasman. Sorry for the delay in response, I've been on leave.

I've run a quick test against one of our wagtail 2.11 systems, and everything looks alright.

@markfinger
Copy link
Collaborator

Thanks again to everyone for the reports and the fixes. 2.1.0 been published with @gasman's fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatible with Wagtail 2.13
4 participants