Add `LearningContentDocumentList`

This commit is contained in:
Daniel Egger 2023-05-26 12:43:57 +02:00
parent 6f65f189de
commit 904d24f566
3 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,31 @@
# Generated by Django 3.2.13 on 2023-05-26 10:34
from django.db import migrations, models
import django.db.models.deletion
import wagtail.blocks
import wagtail.fields
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0083_workflowcontenttype'),
('learnpath', '0004_learningcontentassignment_assignment_type'),
]
operations = [
migrations.CreateModel(
name='LearningContentDocumentList',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('minutes', models.PositiveIntegerField(default=15)),
('description', wagtail.fields.RichTextField(blank=True)),
('content_url', models.TextField(blank=True)),
('documents', wagtail.fields.StreamField([('document', wagtail.blocks.StructBlock([('title', wagtail.blocks.TextBlock()), ('description', wagtail.blocks.TextBlock(default='', required=False)), ('icon_url', wagtail.blocks.TextBlock(default='', required=False)), ('link_display_text', wagtail.blocks.CharBlock(default='Link öffnen', max_length=255)), ('url', wagtail.blocks.TextBlock(default='', required=False)), ('open_window', wagtail.blocks.BooleanBlock(default=False))]))], blank=True, use_json_field=True)),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]

View File

@ -3,13 +3,14 @@ import re
from django.db import models
from django.utils.text import slugify
from wagtail.admin.panels import FieldPanel, PageChooserPanel
from wagtail.fields import RichTextField
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Page
from vbv_lernwelt.assignment.models import AssignmentType
from vbv_lernwelt.core.constants import DEFAULT_RICH_TEXT_FEATURES_WITH_HEADER
from vbv_lernwelt.core.model_utils import find_available_slug
from vbv_lernwelt.course.models import CourseBasePage, CoursePage
from vbv_lernwelt.media_library.content_blocks import LearnMediaBlock
class LearningPath(CourseBasePage):
@ -352,6 +353,29 @@ class LearningContentAssignment(LearningContent):
]
class LearningContentDocumentList(LearningContent):
serialize_field_names = LearningContent.serialize_field_names + [
"documents",
]
parent_page_types = ["learnpath.Circle"]
subpage_types = []
documents = StreamField(
[
("document", LearnMediaBlock()),
],
use_json_field=True,
blank=True,
)
content_panels = [
FieldPanel("title", classname="full title"),
FieldPanel("minutes"),
FieldPanel("description"),
FieldPanel("documents"),
]
def find_slug_with_parent_prefix(page, type_prefix, slug_postfix=None):
parent_slug = page.get_ancestors().exact_type(LearningPath, Circle).last().slug
if parent_slug:

View File

@ -16,6 +16,10 @@ from vbv_lernwelt.learnpath.models import (
LearningSequence,
LearningUnit,
Topic,
LearningContentDocumentList,
)
from vbv_lernwelt.media_library.tests.media_library_factories import (
LearnMediaBlockFactory,
)
@ -172,3 +176,17 @@ class LearningContentAssignmentFactory(wagtail_factories.PageFactory):
class Meta:
model = LearningContentAssignment
class LearningContentDocumentListFactory(wagtail_factories.PageFactory):
title = "Dokumente"
minutes = 0
content_url = ""
description = RichText("")
documents = [
("document", LearnMediaBlockFactory()),
("document", LearnMediaBlockFactory()),
]
class Meta:
model = LearningContentDocumentList