Extract revision and draft state logic from generic views into mixins #9709
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #9710.
An alternate approach to #9190. I initially tried to create a separate mixin for each corresponding model mixin, and dynamically applying the view mixins in
SnippetViewSet
based on the model class. However, that seems to add more complexity as we'll need to have one view mixin for each model, for each view (e.g.CreateViewDraftStateMixin
,EditViewDraftStateMixin
). It will be very hard to make sure all the combinations work correctly, especially with the upcomingLockableMixin
(and soonWorkflowMixin
) integrations.After tinkering around, I think it's worth to just combine all the model mixins logic into a single mixin for each view (
XViewOptionalFeaturesMixin
). This allows us to handle the model mixin combinations in each method in a simpler way (usingif
checks), while still removing the model mixin logic from the generic views.I'd suggest reviewing each individual commit. The last commit combines the mixins for
CreateView
andEditView
into a single mixin as some methods are exactly the same (publish_action()
,form_valid()
, etc.). Not sure if the reusability vs readability tradeoff is worth it, though. I'd be happy to remove that commit if desired.I also noticed some method overrides in snippets views are no longer necessary as of #9221, so I removed them.
Please check the following:
make lint
from the Wagtail root.Please describe additional details for testing this change.
Footnotes
Development Testing ↩