73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
from django.db import models
|
|
from wagtail import blocks
|
|
from wagtail.admin.panels import FieldPanel
|
|
from wagtail.snippets.models import register_snippet
|
|
|
|
from wagtail.documents.blocks import DocumentChooserBlock
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
class VisualisationType(models.TextChoices):
|
|
LEARNING_MEDIA = 'LearningMedia', _('Lernmedien')
|
|
LINK = 'Link', _('Links')
|
|
ANKER = 'Anker', _('Verankerung')
|
|
CROSSREFERENCE = 'CrossReference', _('Querverweise')
|
|
|
|
|
|
@register_snippet
|
|
class MediaLibraryContent(models.Model):
|
|
title = models.TextField()
|
|
description = models.TextField()
|
|
link_display_text = models.CharField(max_length=255)
|
|
# TODO: Revisions only work with wagtail 4.0, can not migrate since wagtail localize is not ready yet.
|
|
# _revisions = GenericRelation("wagtailcore.Revision", related_query_name="media_library_content")
|
|
|
|
panels = [
|
|
FieldPanel('title'),
|
|
FieldPanel('description'),
|
|
FieldPanel('link_display_text'),
|
|
]
|
|
|
|
@property
|
|
def revisions(self):
|
|
return self._revisions
|
|
|
|
|
|
class AnkerBlock(blocks.PageChooserBlock):
|
|
"""
|
|
Verankerung im Lernpfad. Link to a Learning Content.
|
|
"""
|
|
page_type = 'learnpath.LearningUnit'
|
|
|
|
|
|
class LinkBlock(blocks.StructBlock):
|
|
title = blocks.TextBlock(blank=False, null=False)
|
|
description = blocks.TextBlock(default='')
|
|
link_display_text = blocks.CharBlock(max_length=255, default='Link öffnen')
|
|
url = blocks.URLBlock()
|
|
|
|
|
|
class CrossReferenceBlock(blocks.StructBlock):
|
|
title = models.TextField(blank=False, null=False)
|
|
description = blocks.TextBlock(default='')
|
|
link_display_text = blocks.CharBlock(max_length=255, default='Link öffnen')
|
|
category = blocks.PageChooserBlock(page_type='media_library.Category')
|
|
|
|
|
|
class ContentCollection(blocks.StructBlock):
|
|
"""
|
|
Lernmedien, Links, Querverweise, Verankerung
|
|
"""
|
|
title = blocks.TextBlock()
|
|
collection_type = blocks.MultipleChoiceBlock(choices=VisualisationType.choices,
|
|
max_length=20,
|
|
default=VisualisationType.LEARNING_MEDIA)
|
|
contents = blocks.StreamBlock([('Links', LinkBlock()),
|
|
('Documents', DocumentChooserBlock()),
|
|
('Ankers', AnkerBlock()),
|
|
('CrossReference', CrossReferenceBlock())
|
|
])
|
|
|
|
class Meta:
|
|
icon = 'link'
|