60 lines
1.6 KiB
Python
60 lines
1.6 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 wagtail.images.edit_handlers import ImageChooserPanel
|
|
|
|
from book.blocks import DEFAULT_RICH_TEXT_FEATURES
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Module(Page):
|
|
class Meta:
|
|
verbose_name = 'Modul'
|
|
verbose_name_plural = 'Module'
|
|
|
|
order = models.PositiveIntegerField(null=False, blank=False, help_text='Order of the module')
|
|
meta_title = models.CharField(
|
|
max_length=255,
|
|
help_text='e.g. \'Intro\' or \'Modul 1\''
|
|
)
|
|
teaser = models.TextField()
|
|
description = RichTextField(features=DEFAULT_RICH_TEXT_FEATURES)
|
|
|
|
hero_image = models.ForeignKey(
|
|
'wagtailimages.Image',
|
|
null=True,
|
|
blank=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name='+'
|
|
)
|
|
|
|
content_panels = [
|
|
FieldPanel('title', classname="full title"),
|
|
FieldPanel('meta_title', classname="full title"),
|
|
ImageChooserPanel('hero_image'),
|
|
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.Topic']
|
|
|
|
@classmethod
|
|
def get_topic_modules(cls, topic):
|
|
return cls.objects.filter(id__in=topic.get_child_ids()).live()
|