Refactor default settings panel

This commit is contained in:
Ramon Wenger 2022-04-04 17:33:54 +02:00
parent e699ea86f9
commit 200553413a
6 changed files with 19 additions and 29 deletions

View File

@ -2,7 +2,7 @@ import logging
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList
from core.wagtail_utils import StrictHierarchyPage from core.wagtail_utils import StrictHierarchyPage, get_default_settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -16,13 +16,9 @@ class Book(StrictHierarchyPage):
FieldPanel('title', classname="full title") FieldPanel('title', classname="full title")
] ]
settings_panels = [
FieldPanel('slug')
]
edit_handler = TabbedInterface([ edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'), ObjectList(content_panels, heading='Content'),
ObjectList(settings_panels, heading='Settings'), get_default_settings()
]) ])
template = 'generic_page.html' template = 'generic_page.html'

View File

@ -3,7 +3,7 @@ import logging
from django.db import models from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList
from core.wagtail_utils import StrictHierarchyPage from core.wagtail_utils import StrictHierarchyPage, get_default_settings
from users.models import SchoolClass from users.models import SchoolClass
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -21,13 +21,9 @@ class Chapter(StrictHierarchyPage):
FieldPanel('description', classname="full description"), FieldPanel('description', classname="full description"),
] ]
settings_panels = [
FieldPanel('slug')
]
edit_handler = TabbedInterface([ edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'), ObjectList(content_panels, heading='Content'),
ObjectList(settings_panels, heading='Settings'), get_default_settings()
]) ])
template = 'generic_page.html' template = 'generic_page.html'

View File

@ -5,8 +5,8 @@ from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList,
from wagtail.core.blocks import StreamBlock from wagtail.core.blocks import StreamBlock
from wagtail.core.fields import StreamField from wagtail.core.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock from wagtail.images.blocks import ImageChooserBlock
from wagtail.admin.edit_handlers import CommentPanel
from core.wagtail_utils import get_default_settings
from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, DocumentBlock, \ from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, DocumentBlock, \
ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock, \ ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock, \
ThinglinkBlock, InstructionBlock ThinglinkBlock, InstructionBlock
@ -81,14 +81,10 @@ class ContentBlock(StrictHierarchyPage):
StreamFieldPanel('contents') StreamFieldPanel('contents')
] ]
settings_panels = [
FieldPanel('slug'),
CommentPanel()
]
# #
edit_handler = TabbedInterface([ edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'), ObjectList(content_panels, heading='Content'),
ObjectList(settings_panels, heading='Settings'), get_default_settings()
]) ])
parent_page_types = ['books.Chapter'] parent_page_types = ['books.Chapter']

View File

@ -8,7 +8,7 @@ from wagtail.core.fields import RichTextField
from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.images.edit_handlers import ImageChooserPanel
from core.constants import DEFAULT_RICH_TEXT_FEATURES from core.constants import DEFAULT_RICH_TEXT_FEATURES
from core.wagtail_utils import StrictHierarchyPage from core.wagtail_utils import StrictHierarchyPage, get_default_settings
from users.models import SchoolClass from users.models import SchoolClass
@ -42,13 +42,9 @@ class Module(StrictHierarchyPage):
FieldPanel('intro'), FieldPanel('intro'),
] ]
settings_panels = [
FieldPanel('slug')
]
edit_handler = TabbedInterface([ edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'), ObjectList(content_panels, heading='Content'),
ObjectList(settings_panels, heading='Settings'), get_default_settings()
]) ])
template = 'generic_page.html' template = 'generic_page.html'

View File

@ -5,7 +5,7 @@ from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList
from wagtail.core.fields import RichTextField from wagtail.core.fields import RichTextField
from core.constants import DEFAULT_RICH_TEXT_FEATURES from core.constants import DEFAULT_RICH_TEXT_FEATURES
from core.wagtail_utils import StrictHierarchyPage from core.wagtail_utils import StrictHierarchyPage, get_default_settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -30,13 +30,10 @@ class Topic(StrictHierarchyPage):
FieldPanel('description'), FieldPanel('description'),
] ]
settings_panels = [
FieldPanel('slug')
]
edit_handler = TabbedInterface([ edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'), ObjectList(content_panels, heading='Content'),
ObjectList(settings_panels, heading='Settings'), get_default_settings()
]) ])
template = 'generic_page.html' template = 'generic_page.html'

View File

@ -1,4 +1,6 @@
from django.contrib import admin from django.contrib import admin
from wagtail.admin.edit_handlers import CommentPanel
from wagtail.admin.edit_handlers import FieldPanel, ObjectList
from wagtail.core.models import Page from wagtail.core.models import Page
@ -29,3 +31,10 @@ def wagtail_parent_filter(parent_cls, child_cls):
return child_cls.objects.filter(id__in=parent.get_child_ids()).live() return child_cls.objects.filter(id__in=parent.get_child_ids()).live()
return ParentValueFilter return ParentValueFilter
def get_default_settings():
return ObjectList([
FieldPanel('slug'),
CommentPanel()
], heading='Settings')