vbv/server/vbv_lernwelt/competence/models.py

51 lines
1.6 KiB
Python

from django.db import models
from django.utils.text import slugify
from wagtail.admin.panels import FieldPanel
from wagtail.models import Page
from vbv_lernwelt.core.model_utils import find_available_slug
from vbv_lernwelt.learnpath.serializer_helpers import get_it_serializer_class
class CompetenceProfilePage(Page):
parent_page_types = ['course.CoursePage']
subpage_types = ['competence.PerformanceCriteria']
content_panels = [
FieldPanel('title', classname="full title"),
]
def full_clean(self, *args, **kwargs):
self.slug = find_available_slug(slugify(f"{self.get_parent().slug}-competence", allow_unicode=True))
super(CompetenceProfilePage, self).full_clean(*args, **kwargs)
@classmethod
def get_serializer_class(cls):
return get_it_serializer_class(
cls, [
'id', 'title', 'slug', 'type', 'translation_key',
'course',
'children',
]
)
class PerformanceCriteria(Page):
parent_page_types = ['competence.CompetenceProfilePage']
text = models.TextField(default='')
learning_unit = models.ForeignKey(
'learnpath.LearningUnit',
null=True,
blank=True,
on_delete=models.SET_NULL,
)
content_panels = [
FieldPanel('title'),
FieldPanel('learning_unit'),
]
def full_clean(self, *args, **kwargs):
self.slug = find_available_slug(slugify(f"{self.get_parent()}-crit-{self.title}", allow_unicode=True))
super(PerformanceCriteria, self).full_clean(*args, **kwargs)