0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 05:02:57 +01:00

Add status side panel to generic CreateView and simplify snippets CreateView

This commit is contained in:
Sage Abdullah 2024-01-09 15:03:14 +00:00
parent 47d6a8e01f
commit dae20c2038
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217
6 changed files with 41 additions and 45 deletions

View File

@ -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 {

View File

@ -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 %}

View File

@ -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

View File

@ -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 %}
<form action="{{ action_url }}" method="POST" novalidate{% if form.is_multipart %} enctype="multipart/form-data"{% endif %} data-edit-form>
{% csrf_token %}
<div class="nice-padding">
{{ panel.render_form_content }}
</div>
<footer class="footer">
<nav class="actions actions--primary footer__container w-grid" aria-label="{% trans 'Actions' %}">
{{ action_menu.render_html }}
</nav>
</footer>
</form>
{% endblock %}
{% block extra_css %}
{{ block.super }}
{{ media.css }}
{% block actions %}
<footer class="footer">
<nav class="actions actions--primary footer__container w-grid" aria-label="{% trans 'Actions' %}">
{{ action_menu.render_html }}
</nav>
</footer>
{% endblock %}
{% block extra_js %}
{{ block.super }}
{% include "wagtailadmin/pages/_editor_js.html" %}
{{ media.js }}
<script>
// Set wagtailConfig.ACTIVE_CONTENT_LOCALE if this is a translated page

View File

@ -87,7 +87,7 @@ class TestCustomIcon(BaseSnippetViewSetTests):
# TODO: Some of these views have been migrated to use the slim_header
# only, so there is no header_icon anymore.
# ("list", []),
("add", []),
# ("add", []),
("edit", [pk]),
("delete", [pk]),
# ("usage", [pk]),

View File

@ -271,21 +271,9 @@ class CreateView(generic.CreateEditViewOptionalFeaturesMixin, generic.CreateView
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
self.form = context.get("form")
action_menu = self._get_action_menu()
side_panels = self.get_side_panels()
media = context.get("media") + MediaContainer([action_menu, side_panels]).media
context.update(
{
"model_opts": self.model._meta,
"action_menu": action_menu,
"side_panels": side_panels,
"media": media,
}
)
context["media"] += action_menu.media
context["action_menu"] = action_menu
return context