From 585d3e33857243035054eb988fe2814dd08999c9 Mon Sep 17 00:00:00 2001 From: LB Johnston Date: Sun, 11 Feb 2024 17:27:55 +1000 Subject: [PATCH] Adopt Stimulus `w-formset` attributes in Workflow pages basic formset - Use the Wagtail admin formset mixin to adopt new data attributes on core form parts - Update the edit/create templates to put the attributes on the remaining elements - Add basic unit tests for smoke testing data attributes - Remove CSP incompatible inline scripts approach - Remove the now unused standalone static build/imports for the group edit view as this will not be needed - Ensure that the edit workflow form does not render any JS or attributes when the pages are not actually editable (workflow disabled) --- wagtail/admin/forms/workflows.py | 15 +--- .../wagtailadmin/workflows/create.html | 2 +- .../wagtailadmin/workflows/edit.html | 2 +- .../includes/workflow_pages_form.html | 2 +- .../includes/workflow_pages_formset.html | 27 ++------ wagtail/admin/tests/test_workflows.py | 69 +++++++++++++++++++ wagtail/admin/views/workflows.py | 10 ++- 7 files changed, 87 insertions(+), 40 deletions(-) diff --git a/wagtail/admin/forms/workflows.py b/wagtail/admin/forms/workflows.py index a4deb73a10..438cd07dc4 100644 --- a/wagtail/admin/forms/workflows.py +++ b/wagtail/admin/forms/workflows.py @@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy from wagtail.admin import widgets from wagtail.admin.forms import WagtailAdminModelForm +from wagtail.admin.forms.formsets import BaseFormSetMixin from wagtail.admin.panels import FieldPanel, InlinePanel, ObjectList from wagtail.admin.widgets.workflows import AdminTaskChooser from wagtail.coreutils import get_content_type_label, get_model_string @@ -121,19 +122,7 @@ class WorkflowPageForm(forms.ModelForm): ) -class BaseWorkflowPagesFormSet(forms.BaseInlineFormSet): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - for form in self.forms: - form.fields["DELETE"].widget = forms.HiddenInput() - - @property - def empty_form(self): - empty_form = super().empty_form - empty_form.fields["DELETE"].widget = forms.HiddenInput() - return empty_form - +class BaseWorkflowPagesFormSet(BaseFormSetMixin, forms.BaseInlineFormSet): def clean(self): """Checks that no two forms refer to the same page object""" if any(self.errors): diff --git a/wagtail/admin/templates/wagtailadmin/workflows/create.html b/wagtail/admin/templates/wagtailadmin/workflows/create.html index a87eb51c04..abe60b56b8 100644 --- a/wagtail/admin/templates/wagtailadmin/workflows/create.html +++ b/wagtail/admin/templates/wagtailadmin/workflows/create.html @@ -5,7 +5,7 @@ {{ edit_handler.render_form_content }}
- {% panel id="workflow-pages" icon="doc-empty-inverse" heading=_("Assign your workflow to pages") %} + {% panel id="workflow-pages" icon="doc-empty-inverse" heading=_("Assign your workflow to pages") attrs=pages_formset.attrs %} {% include "wagtailadmin/workflows/includes/workflow_pages_formset.html" with formset=pages_formset %} {% endpanel %} diff --git a/wagtail/admin/templates/wagtailadmin/workflows/edit.html b/wagtail/admin/templates/wagtailadmin/workflows/edit.html index 8969293d99..73ac219fae 100644 --- a/wagtail/admin/templates/wagtailadmin/workflows/edit.html +++ b/wagtail/admin/templates/wagtailadmin/workflows/edit.html @@ -5,7 +5,7 @@ {{ edit_handler.render_form_content }}
- {% panel id="workflow-pages" icon="doc-empty-inverse" heading=_("Assign your workflow to pages") %} + {% panel id="workflow-pages" icon="doc-empty-inverse" heading=_("Assign your workflow to pages") attrs=pages_formset.attrs %} {% if workflow.active %}

{% icon name='help' %} diff --git a/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_form.html b/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_form.html index e2b92cee67..df877e1f1e 100644 --- a/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_form.html +++ b/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_form.html @@ -5,5 +5,5 @@ - + diff --git a/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_formset.html b/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_formset.html index 3ac32071b4..89de2e45ce 100644 --- a/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_formset.html +++ b/wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_pages_formset.html @@ -20,9 +20,9 @@ - + {% for form in formset.forms %} - + {% if form.non_field_errors %}

{% for error in form.non_field_errors %} @@ -36,29 +36,12 @@ -