skillbox/server/book/models/chapter.py

39 lines
932 B
Python

import logging
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, \
ObjectList
from wagtail.core.models import Page
logger = logging.getLogger(__name__)
class Chapter(Page):
class Meta:
verbose_name = 'Kapitel'
verbose_name_plural = 'Kapitel'
content_panels = [
FieldPanel('title', classname="full title"),
]
settings_panels = [
FieldPanel('slug')
]
edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'),
ObjectList(settings_panels, heading='Settings'),
])
template = 'generic_page.html'
parent_page_types = ['book.Module']
subpage_types = ['book.ContentBlock']
def get_child_ids(self):
return self.get_children().values_list('id', flat=True)
@classmethod
def get_module_chapters(cls, module):
return cls.objects.filter(id__in=module.get_child_ids()).live()