mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
Add test examples of snippet models with panels/edit_handler on the viewset
This commit is contained in:
parent
f41098fd26
commit
e2c7b640d9
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user