vbv/server/vbv_lernwelt/media_library/content_blocks.py

66 lines
1.9 KiB
Python

from django.db import models
from wagtail import blocks
from wagtail.admin.panels import FieldPanel
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.snippets.models import register_snippet
@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 AnchorBlock(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.MediaCategoryPage")
class MediaContentCollection(blocks.StructBlock):
"""
Lernmedien, Links, Querverweise, Verankerung
"""
title = blocks.TextBlock()
contents = blocks.StreamBlock(
[
("Links", LinkBlock()),
("Documents", DocumentChooserBlock()),
("Ankers", AnchorBlock()),
("CrossReference", CrossReferenceBlock()),
]
)
class Meta:
icon = "link"