50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import logging
|
|
|
|
from django.db import models
|
|
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, \
|
|
ObjectList
|
|
from wagtail.core.fields import RichTextField
|
|
from wagtail.core.models import Page
|
|
|
|
from book.blocks import DEFAULT_RICH_TEXT_FEATURES
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Topic(Page):
|
|
class Meta:
|
|
verbose_name = 'Thema'
|
|
verbose_name_plural = 'Themen'
|
|
|
|
order = models.PositiveIntegerField(null=False, blank=False, help_text='Order of the topic')
|
|
teaser = models.TextField()
|
|
description = RichTextField(features=DEFAULT_RICH_TEXT_FEATURES)
|
|
|
|
content_panels = [
|
|
FieldPanel('title', classname="full title"),
|
|
FieldPanel('order'),
|
|
FieldPanel('teaser'),
|
|
FieldPanel('description'),
|
|
]
|
|
|
|
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.Book']
|
|
subpage_types = ['book.Module']
|
|
|
|
def get_child_ids(self):
|
|
return self.get_children().values_list('id', flat=True)
|
|
|
|
@classmethod
|
|
def get_book_topics(cls, book):
|
|
return cls.objects.filter(id__in=book.get_child_ids()).live()
|