From dae20c2038de2049d6ef3af9fcae01f7433a12b3 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Tue, 9 Jan 2024 15:03:14 +0000 Subject: [PATCH] Add status side panel to generic CreateView and simplify snippets CreateView --- client/scss/components/_footer.scss | 5 +++ .../templates/wagtailadmin/generic/form.html | 4 +- wagtail/admin/views/generic/models.py | 18 +++++++- .../wagtailsnippets/snippets/create.html | 41 +++++++------------ wagtail/snippets/tests/test_viewset.py | 2 +- wagtail/snippets/views/snippets.py | 16 +------- 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/client/scss/components/_footer.scss b/client/scss/components/_footer.scss index 616b9d9b8b..ee67a3d508 100644 --- a/client/scss/components/_footer.scss +++ b/client/scss/components/_footer.scss @@ -20,6 +20,11 @@ &__emphasise-span-tags span { color: theme('colors.warning.100'); } + + // Don't apply horizontal margins if nice-padding is applied in the parent + .nice-padding & { + margin-inline: 0; + } } .footer__container { diff --git a/wagtail/admin/templates/wagtailadmin/generic/form.html b/wagtail/admin/templates/wagtailadmin/generic/form.html index 30f728f563..5e6848b04e 100644 --- a/wagtail/admin/templates/wagtailadmin/generic/form.html +++ b/wagtail/admin/templates/wagtailadmin/generic/form.html @@ -43,10 +43,10 @@ {% block extra_js %} {{ block.super }} - {{ form.media.js }} + {{ media.js }} {% endblock %} {% block extra_css %} {{ block.super }} - {{ form.media.css }} + {{ media.css }} {% endblock %} diff --git a/wagtail/admin/views/generic/models.py b/wagtail/admin/views/generic/models.py index eee6405535..5e48694631 100644 --- a/wagtail/admin/views/generic/models.py +++ b/wagtail/admin/views/generic/models.py @@ -588,10 +588,25 @@ class CreateView( def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + self.form = context.get("form") + side_panels = self.get_side_panels() context["action_url"] = self.get_add_url() context["submit_button_label"] = self.submit_button_label + context["side_panels"] = side_panels + context["media"] += side_panels.media return context + def get_side_panels(self): + side_panels = [ + StatusSidePanel( + self.form.instance, + self.request, + locale=self.locale, + translations=self.translations, + ) + ] + return MediaContainer(side_panels) + def get_translations(self): add_url = self.get_add_url() return [ @@ -833,11 +848,10 @@ class EditView( context = super().get_context_data(**kwargs) self.form = context.get("form") side_panels = self.get_side_panels() - media = context.get("media") + side_panels.media context["action_url"] = self.get_edit_url() context["history_url"] = self.get_history_url() context["side_panels"] = side_panels - context["media"] = media + context["media"] += side_panels.media context["submit_button_label"] = self.submit_button_label context["can_delete"] = ( self.permission_policy is None diff --git a/wagtail/snippets/templates/wagtailsnippets/snippets/create.html b/wagtail/snippets/templates/wagtailsnippets/snippets/create.html index e17d6de403..864d8baee1 100644 --- a/wagtail/snippets/templates/wagtailsnippets/snippets/create.html +++ b/wagtail/snippets/templates/wagtailsnippets/snippets/create.html @@ -1,37 +1,26 @@ -{% extends "wagtailadmin/base.html" %} +{% extends "wagtailadmin/generic/create.html" %} {% load i18n wagtailadmin_tags %} -{% block titletag %}{% blocktrans trimmed with snippet_type_name=model_opts.verbose_name %}New {{ snippet_type_name }}{% endblocktrans %}{% endblock %} -{% block bodyclass %}editor-view{% endblock %} -{% block content %} + +{% block slim_header %} + {% comment %} + We can't use the `only` keyword yet, because the SnippetStatusSidePanel still rely on some + context variables from the view. As a result, we can't reuse the include from the generic + template and have to copy it here without the `only` keyword. + {% endcomment %} {% include 'wagtailadmin/shared/headers/slim_header.html' with breadcrumbs_items=breadcrumbs_items side_panels=side_panels history_url=history_url %} - - {% trans "New" as new_str %} - {% include "wagtailadmin/shared/header.html" with title=new_str subtitle=model_opts.verbose_name icon=header_icon merged=1 only %} - -
- {% csrf_token %} - -
- {{ panel.render_form_content }} -
- -
- -
-
- {% endblock %} -{% block extra_css %} - {{ block.super }} - {{ media.css }} +{% block actions %} + {% endblock %} + {% block extra_js %} {{ block.super }} {% include "wagtailadmin/pages/_editor_js.html" %} - {{ media.js }}