73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
from django.db import models
|
|
from django.utils.text import slugify
|
|
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
|
|
from wagtail.core.fields import RichTextField, StreamField
|
|
from wagtail.images.blocks import ImageChooserBlock
|
|
|
|
from books.blocks import DocumentBlock, GeniallyBlock, InfogramBlock, InstrumentTextBlock, LinkBlock, SectionTitleBlock, \
|
|
SubtitleBlock, ThinglinkBlock, VideoBlock
|
|
from core.constants import DEFAULT_RICH_TEXT_FEATURES
|
|
from core.wagtail_utils import StrictHierarchyPage
|
|
|
|
LANGUAGE_COMMUNICATION = 'language_communication'
|
|
SOCIETY = 'society'
|
|
INTERDISCIPLINARY = 'interdisciplinary'
|
|
|
|
|
|
class InstrumentType(models.Model):
|
|
CATEGORY_CHOICES = (
|
|
(LANGUAGE_COMMUNICATION, 'Sprache & Kommunikation'),
|
|
(SOCIETY, 'Gesellschaft'),
|
|
(INTERDISCIPLINARY, 'Überfachliches Instrument'),
|
|
)
|
|
|
|
name = models.CharField(max_length=255, unique=True)
|
|
category = models.CharField(
|
|
max_length=100,
|
|
choices=CATEGORY_CHOICES
|
|
)
|
|
|
|
@property
|
|
def type(self):
|
|
return slugify(self.name.lower())
|
|
|
|
def __str__(self):
|
|
return self.type
|
|
|
|
|
|
class BasicKnowledge(StrictHierarchyPage):
|
|
parent_page_types = ['books.book']
|
|
|
|
intro = RichTextField(features=DEFAULT_RICH_TEXT_FEATURES, default='', blank=True)
|
|
|
|
contents = StreamField([
|
|
('text_block', InstrumentTextBlock()),
|
|
('image_block', ImageChooserBlock()),
|
|
('link_block', LinkBlock()),
|
|
('video_block', VideoBlock()),
|
|
('document_block', DocumentBlock()),
|
|
('section_title', SectionTitleBlock()),
|
|
('infogram_block', InfogramBlock()),
|
|
('genially_block', GeniallyBlock()),
|
|
('thinglink_block', ThinglinkBlock()),
|
|
('subtitle', SubtitleBlock()),
|
|
], null=True, blank=True)
|
|
|
|
new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT, related_name='instruments')
|
|
|
|
old_type = models.CharField(
|
|
max_length=100,
|
|
choices=InstrumentType.CATEGORY_CHOICES,
|
|
blank=True
|
|
)
|
|
|
|
content_panels = [
|
|
FieldPanel('title', classname="full title"),
|
|
FieldPanel('new_type'),
|
|
FieldPanel('intro'),
|
|
StreamFieldPanel('contents')
|
|
]
|
|
|
|
class Meta:
|
|
verbose_name = 'Instrument'
|