From e2c7b640d9163bbdfa24b279024d8d95c3dd50b0 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Fri, 31 Mar 2023 13:01:51 +0100 Subject: [PATCH] Add test examples of snippet models with panels/edit_handler on the viewset --- wagtail/test/testapp/models.py | 13 ++----------- wagtail/test/testapp/wagtail_hooks.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/wagtail/test/testapp/models.py b/wagtail/test/testapp/models.py index eea6611f2f..faba76ce50 100644 --- a/wagtail/test/testapp/models.py +++ b/wagtail/test/testapp/models.py @@ -984,13 +984,7 @@ register_snippet(RevisableModel) class RevisableChildModel(RevisableModel): secret_text = models.TextField(blank=True, default="") - panels = [ - FieldPanel("text"), - FieldPanel("secret_text", permission="superuser"), - ] - - -register_snippet(RevisableChildModel) + # The edit_handler is defined on the viewset class RevisableGrandChildModel(RevisableChildModel): @@ -1001,10 +995,7 @@ class RevisableGrandChildModel(RevisableChildModel): class DraftStateModel(DraftStateMixin, LockableMixin, RevisionMixin, models.Model): text = models.TextField() - panels = [ - FieldPanel("text"), - PublishingPanel(), - ] + # The panels are defined on the viewset def __str__(self): return self.text diff --git a/wagtail/test/testapp/wagtail_hooks.py b/wagtail/test/testapp/wagtail_hooks.py index 0e93fdb434..34fd05e954 100644 --- a/wagtail/test/testapp/wagtail_hooks.py +++ b/wagtail/test/testapp/wagtail_hooks.py @@ -6,6 +6,12 @@ from wagtail import hooks from wagtail.admin.action_menu import ActionMenuItem from wagtail.admin.filters import WagtailFilterSet from wagtail.admin.menu import MenuItem +from wagtail.admin.panels import ( + FieldPanel, + ObjectList, + PublishingPanel, + TabbedInterface, +) from wagtail.admin.rich_text.converters.html_to_contentstate import BlockElementHandler from wagtail.admin.search import SearchArea from wagtail.admin.site_summary import SummaryItem @@ -19,6 +25,7 @@ from wagtail.test.testapp.models import ( DraftStateModel, FullFeaturedSnippet, ModeratedModel, + RevisableChildModel, ) from .forms import FavouriteColourForm @@ -260,11 +267,30 @@ class FullFeaturedSnippetViewSet(SnippetViewSet): return self.model._default_manager.all().exclude(text__contains="[HIDDEN]") +class RevisableChildModelViewSet(SnippetViewSet): + edit_handler = TabbedInterface( + [ + ObjectList([FieldPanel("text")], heading="Main"), + ObjectList( + [FieldPanel("secret_text", permission="superuser")], + heading="Other", + help_text="Other panels help text", + ), + ], + help_text="Top-level help text", + ) + + class DraftStateModelViewSet(SnippetViewSet): list_filter = ["text", "first_published_at"] search_fields = ["text"] search_backend_name = None + panels = [ + FieldPanel("text"), + PublishingPanel(), + ] + class ModeratedModelViewSet(SnippetViewSet): list_filter = { @@ -274,5 +300,6 @@ class ModeratedModelViewSet(SnippetViewSet): register_snippet(FullFeaturedSnippet, viewset=FullFeaturedSnippetViewSet) +register_snippet(RevisableChildModel, viewset=RevisableChildModelViewSet) register_snippet(DraftStateModel, viewset=DraftStateModelViewSet) register_snippet(ModeratedModel, viewset=ModeratedModelViewSet)