Hide schedule publishing dialog toggle if PublishingPanel is not present

pull/9226/head
Sage Abdullah 2022-09-15 14:39:15 +01:00 zatwierdzone przez Matt Westcott
rodzic 4d9fff454c
commit 66d0bfa13c
8 zmienionych plików z 72 dodań i 3 usunięć

Wyświetl plik

@ -154,6 +154,10 @@ class WagtailAdminPageForm(WagtailAdminModelForm):
if not self.show_comments_toggle:
del self.fields["comment_notifications"]
@property
def show_schedule_publishing_toggle(self):
return "go_live_at" in self.__class__.base_fields
@property
def show_comments_toggle(self):
return "comments" in self.__class__.formsets

Wyświetl plik

@ -44,7 +44,7 @@
{{ live_expire_at }}
</div>
</div>
{% if not has_draft_publishing_schedule and not page_perms.page_locked and not in_explorer %}
{% if show_schedule_publishing_toggle and not has_draft_publishing_schedule and not page_perms.page_locked %}
{% trans 'Edit schedule' as edit_schedule_text %}
{% dialog_toggle class_name='w-bg-transparent w-text-14 w-p-0 w-text-secondary hover:w-text-secondary-600 w-inline-flex w-justify-center w-transition' dialog_id="schedule-publishing-dialog" text=edit_schedule_text %}
{% endif %}
@ -152,7 +152,7 @@
{% endif %}
{% endif %}
</div>
{% if not page_perms.page_locked and not in_explorer %}
{% if show_schedule_publishing_toggle and not page_perms.page_locked %}
{% trans 'Edit schedule' as edit_schedule_text %}
{% dialog_toggle class_name='w-bg-transparent w-text-14 w-p-0 w-text-secondary hover:w-text-secondary-600 w-inline-flex w-justify-center w-transition' dialog_id="schedule-publishing-dialog" text=edit_schedule_text %}
{% endif %}
@ -161,7 +161,7 @@
{% elif not has_live_publishing_schedule %}
<div class="w-flex w-justify-between w-items-center w-w-full">
<div class="w-ml-8 w-pr-4 w-label-3">{% trans 'No publishing schedule set' %}</div>
{% if not page_perms.page_locked and not in_explorer %}
{% if show_schedule_publishing_toggle and not page_perms.page_locked %}
{% trans 'Set schedule' as set_schedule_text %}
{% dialog_toggle class_name='w-bg-transparent w-text-14 w-p-0 w-text-secondary hover:w-text-secondary-600 w-inline-flex w-justify-center w-transition' dialog_id="schedule-publishing-dialog" text=set_schedule_text %}
{% endif %}

Wyświetl plik

@ -22,6 +22,7 @@ from wagtail.admin.panels import (
MultiFieldPanel,
ObjectList,
PageChooserPanel,
PublishingPanel,
TabbedInterface,
extract_panel_definitions_from_model_class,
get_form_for_model,
@ -1617,3 +1618,54 @@ class TestCommentPanel(TestCase, WagtailTestUtils):
self.assertTrue(reply_forms[1].is_valid())
# The existing reply was from the same user, so should be deletable
class TestPublishingPanel(TestCase, WagtailTestUtils):
fixtures = ["test.json"]
def setUp(self):
self.user = self.login()
unbound_object_list = ObjectList([PublishingPanel()])
self.object_list = unbound_object_list.bind_to_model(EventPage)
self.tabbed_interface = TabbedInterface([unbound_object_list]).bind_to_model(
EventPage
)
self.EventPageForm = self.object_list.get_form_class()
self.event_page = EventPage.objects.get(slug="christmas")
def test_schedule_publishing_toggle_toggle_shown(self):
"""
Test that the schedule publishing toggle is shown for a TabbedInterface containing PublishingPanel, and disabled otherwise
"""
form_class = self.tabbed_interface.get_form_class()
form = form_class()
self.assertTrue(form.show_schedule_publishing_toggle)
tabbed_interface_without_publishing_panel = TabbedInterface(
[ObjectList(self.event_page.content_panels)]
).bind_to_model(EventPage)
form_class = tabbed_interface_without_publishing_panel.get_form_class()
form = form_class()
self.assertFalse(form.show_schedule_publishing_toggle)
def test_publishing_panel_shown_by_default(self):
"""
Test that the publishing panel is present by default
"""
self.assertTrue(
any(isinstance(panel, PublishingPanel) for panel in Page.settings_panels)
)
form_class = Page.get_edit_handler().get_form_class()
form = form_class()
self.assertTrue(form.show_schedule_publishing_toggle)
def test_form(self):
"""
Check that the form has the scheduled publishing fields
"""
form = self.EventPageForm(instance=self.event_page, for_user=self.user)
self.assertIn("go_live_at", form.base_fields)
self.assertIn("expire_at", form.base_fields)

Wyświetl plik

@ -34,12 +34,16 @@ class BaseStatusSidePanel(BaseSidePanel):
def __init__(
self,
*args,
show_schedule_publishing_toggle=None,
live_object=None,
scheduled_page=None,
in_explorer=False,
**kwargs,
):
super().__init__(*args, **kwargs)
self.show_schedule_publishing_toggle = (
show_schedule_publishing_toggle and not in_explorer
)
self.live_object = live_object
self.scheduled_page = scheduled_page
self.in_explorer = in_explorer
@ -57,6 +61,9 @@ class BaseStatusSidePanel(BaseSidePanel):
return {}
context = {
# The dialog toggle can be hidden (e.g. if PublishingPanel is not present)
# but the scheduled publishing info should still be shown
"show_schedule_publishing_toggle": self.show_schedule_publishing_toggle,
# These are the dates that show up with the unticked calendar icon,
# aka "draft schedule"
"draft_go_live_at": None,
@ -277,6 +284,7 @@ class PageSidePanels(BaseSidePanels):
*,
preview_enabled,
comments_enabled,
show_schedule_publishing_toggle,
live_page=None,
scheduled_page=None,
in_explorer=False,
@ -287,6 +295,7 @@ class PageSidePanels(BaseSidePanels):
PageStatusSidePanel(
page,
self.request,
show_schedule_publishing_toggle=show_schedule_publishing_toggle,
live_object=live_page,
scheduled_page=scheduled_page,
in_explorer=in_explorer,

Wyświetl plik

@ -339,6 +339,7 @@ class CreateView(TemplateResponseMixin, ContextMixin, HookResponseMixin, View):
self.page,
preview_enabled=True,
comments_enabled=self.form.show_comments_toggle,
show_schedule_publishing_toggle=self.form.show_schedule_publishing_toggle,
)
context.update(

Wyświetl plik

@ -845,6 +845,7 @@ class EditView(TemplateResponseMixin, ContextMixin, HookResponseMixin, View):
scheduled_page=self.scheduled_page,
preview_enabled=True,
comments_enabled=self.form.show_comments_toggle,
show_schedule_publishing_toggle=self.form.show_schedule_publishing_toggle,
)
context.update(

Wyświetl plik

@ -97,6 +97,7 @@ def index(request, parent_page_id=None):
side_panels = PageSidePanels(
request,
parent_page.get_latest_revision_as_object(),
show_schedule_publishing_toggle=False,
live_page=parent_page.specific,
scheduled_page=parent_page.get_scheduled_revision_as_object(),
in_explorer=True,

Wyświetl plik

@ -57,6 +57,7 @@ def revisions_revert(request, page_id, revision_id):
page,
preview_enabled=True,
comments_enabled=form.show_comments_toggle,
show_schedule_publishing_toggle=form.show_schedule_publishing_toggle,
)
user_avatar = render_to_string(