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
Phase out special-purpose field panel types #7684
Conversation
Manage this branch in SquashTest this branch here: https://gasmancleanupremove-chooser-pa-b1ya1.squash.io |
Is it possible to also do away with PageChooserPanel by making the can choose root and page type options pass through via some other kwarg? Maybe attrs or similar? Maybe we kill it and make |
The only added functionality in PageChooserPanel now is to pass the
can be rewritten as:
The latter is more wordy and 'low-level', so I'm hesitant to push it as a recommended replacement for PageChooserPanel in that situation. I'd also be reluctant to hard-code any page-chooser-specific special cases in FieldPanel, which would rule out something like
and while there might be a middle ground like
...I'm not sure if that's enough of an improvement to be worthwhile, or whether the As a bit of additional context - I'm intending that the next step on this path will be to make
...and hopefully along the way we'll introduce template components so that defining a wrapper like MultiFieldPanel is more a case of overriding a template and less deep Wagtail "bind an instance to a form" voodoo. In that future scenario, then, I think PageChooserPanel in its current form will sit nicely as a 'power user' feature that you'll drop in if you want more control over how the form behaves - for a simple setup it'll be
but the 'advanced' version is:
|
5a054ad
to
0e8f476
Compare
@gasman We could adopt something similar to the pattern used by django.contrib.admin.Modeladmin.fieldsets
Example:
|
@ababic I see the panels definition as being a 'pluggable' thing, where it would be a routine task for developers to create their own panel types if they so wish - so I'm reluctant to attach any syntactic special status to the built-in ones. With some well-thought-out API design I think we can make things readable enough that that isn't necessary:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! It's really great to see such a large reduction in complexity too
Only thing I wanted to pick up on was the title new forms doc. Also, do you think we should follow the how-to guide recommendations for this?
docs/extending/forms.md
Outdated
@@ -0,0 +1,58 @@ | |||
# Forms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a more descriptive title to make this easier to find? For example "Globally overriding form widgets"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone for "Using forms in admin views", as the instructions for overriding widgets are only one section of it. I think there's a risk with going overly specific on these titles, where people have to do extra thinking to figure out if it corresponds to the problem they're trying to solve - if they're coming to the docs with the question "how do I build a form with the Wagtail look and feel", they might not immediately make the connection to "overriding form widgets".
09cbb1f
to
e84dd5e
Compare
All built-in choosers use the standard field_panel_field.html template - it's probably been this way since Wagtail 1.0, when choosers got their own Widget classes rather than just being HTML decoration around a HiddenInput. As a result, the additional template context they pass (e.g. self.object_type_name) is redundant. If any third-party chooser panels exist that do need them (which is unlikely, if they just copy the existing ones), they should override render_as_field themselves to pass whatever context they need.
Removing the test is justified as this isn't a public-facing method; it's just a helper to get the object data onto the template, and the test_render_as_field test already confirms that's working correctly.
This has been part of django-modelcluster's ClusterForm since 3.1: wagtail/django-modelcluster#73
…et for a ForeignKey to a specific model This means that pages, images, documents and snippets will use the approprate chooser widget automatically without having to specify it explicitly in the form definition or use a *ChooserPanel in the edit handler.
These are no longer necessary now that the correct widgets are selected at the form level.
…register their own form fields with WagtailAdminModelForm
…s to a page subclass
…lowed by PageChooserPanel's page_type argument
…s handled by the widget
…get_comparison_class on panels
e84dd5e
to
ea5530b
Compare
…y identical to FieldPanel
…ead of hard-coding an exception in StreamFieldPanel
…t have to override it
…treamFieldPanel to FieldPanel
ea5530b
to
b937dad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thanks!
…2.17 as a result of the move to phase out special-purpose field panel types wagtail/wagtail#7684
* Pass JSON to Page.with_content_json and tidy up JSON passed during convert alias Page revisions now use a JSONField as of wagtail/wagtail#8024 * Fix PageChooserPanel.target_models no longer available in Wagtail >= 2.17 as a result of the move to phase out special-purpose field panel types wagtail/wagtail#7684
This change makes it possible to use
FieldPanel
for all field types, makingStreamFieldPanel
,RichTextFieldPanel
,ImageChooserPanel
,DocumentChooserPanel
andSnippetChooserPanel
obsolete andPageChooserPanel
almost obsolete (it's still provided as a convenience for passing thepage_type
orcan_choose_root
arguments, although even this can be replaced with aFieldPanel
with an appropriatewidget
). This is achieved in part by a new extension toWagtailAdminModelForm
, where apps can register their own form widgets to be used for a given model field type (so that, for example, a foreign key to Image always uses the AdminImageChooser widget, without having to specify it explicitly via the form class or EditHandler definition).One thing that might need more consideration is the removal of docs for ImageChooserPanel and DocumentChooserPanel - these currently seem to be written as if they're the first introduction to the image and document models. If this is indeed the case (which wouldn't be great, as these are reference docs rather than howto docs...) we should probably add them back as a new first section on topics/images, and a new topics/documents page.
We might also want to note that if people have deliberately chosen to use FieldPanel instead of a chooser panel (or, for non-edit-handler-based forms, omitted specifying a chooser widget) because a plain dropdown works better for their use case, they'll now need to specify the Select widget explicitly.