vbv/server/vbv_lernwelt/learnpath/models.py

131 lines
3.1 KiB
Python

# Create your models here.
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel, PageChooserPanel, InlinePanel
from wagtail.core.blocks import StreamBlock
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from modelcluster.fields import ParentalKey
from vbv_lernwelt.learnpath.models_learning_unit_content import WebBasedTrainingBlock, VideoBlock
class LearningPath(Page):
#PageChooserPanel('related_page', 'demo.PublisherPage'),
content_panels = Page.content_panels + [
FieldPanel('title', classname="full"),
InlinePanel('topics', label="Topics"),
]
subpage_types = ['learnpath.Topic']
class Meta:
verbose_name = "Learning Path"
def __str__(self):
return f"{self.title}"
class Topic(Page):
is_visible = models.BooleanField(default=True)
learning_path = ParentalKey(
'learnpath.LearningPath',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='topics',
)
content_panels = Page.content_panels + [
FieldPanel('is_visible', classname="full"),
PageChooserPanel('learning_path', 'learnpath.LearningPath'),
]
parent_page_types = ['learnpath.LearningPath']
subpage_types = ['learnpath.Circle']
class Meta:
verbose_name = "Topic"
def __str__(self):
return f"{self.title}"
class Circle(Page):
description = models.TextField(default="", blank=True)
goals = models.TextField(default="", blank=True)
parent_page_types = ['learnpath.Topic']
subpage_types = ['learnpath.LearningSequence']
content_panels = Page.content_panels + [
FieldPanel('description'),
FieldPanel('goals'),
#InlinePanel('circle', label="Learning Sequences"),
]
class Meta:
verbose_name = "Circle"
def __str__(self):
return f"{self.title}"
IN_CIRCLE = 'INCIRCLE'
START = 'START'
END = 'END'
LEARNING_SEQUENCE_CATEGORIES = [
(IN_CIRCLE, 'In Circle'),
(START, 'Start'),
(END, 'End')
]
class LearningSequence(Page):
# TODO: How to do a icon choice field?
category = models.CharField(max_length=16, choices=LEARNING_SEQUENCE_CATEGORIES, default=IN_CIRCLE)
parent_page_types = ['learnpath.Circle']
subpage_types = ['learnpath.LearningUnit']
class Meta:
verbose_name = "Learning Sequence"
def __str__(self):
return f"{self.title}"
class LearningUnit(Page):
# TODO: Review model architecture, is the stream fiel the right thing here?
parent_page_types = ['learnpath.LearningSequence']
content_blocks = [
('web_based_training', WebBasedTrainingBlock()),
('video', VideoBlock()),
]
contents = StreamField(StreamBlock(content_blocks),
null=True, blank=True, min_num=1, max_num=1)
content_panels = [
FieldPanel('title', classname="full title"),
StreamFieldPanel('contents')
]
subpage_types = []
class Meta:
verbose_name = "Learning Unit"
def __str__(self):
return f"{self.title}"