Add course_category to LearningUnit

This commit is contained in:
Daniel Egger 2022-09-27 16:32:01 +02:00
parent 9c77526646
commit 46998668d8
16 changed files with 127 additions and 74 deletions

View File

@ -17,5 +17,5 @@ def create_default_competence_profile():
parent=competence_profile_page, parent=competence_profile_page,
title='B1.3 Fahrzeug', title='B1.3 Fahrzeug',
text='Innerhalb des Handlungsfelds «Fahrzeug» bin ich fähig, die Ziele und Pläne des Kunden zu ergründen (SOLL).', text='Innerhalb des Handlungsfelds «Fahrzeug» bin ich fähig, die Ziele und Pläne des Kunden zu ergründen (SOLL).',
learning_unit=LearningUnit.objects.get(slug='versicherungsvermittlerin-lp-circle-analyse-lu-auto-verkaufen'), learning_unit=LearningUnit.objects.get(slug='versicherungsvermittlerin-lp-circle-analyse-lu-fahrzeug'),
) )

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2022-09-27 13:54 # Generated by Django 3.2.13 on 2022-09-27 14:26
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -10,7 +10,6 @@ class Migration(migrations.Migration):
dependencies = [ dependencies = [
('wagtailcore', '0069_log_entry_jsonfield'), ('wagtailcore', '0069_log_entry_jsonfield'),
('learnpath', '0002_alter_learningcontent_contents'),
] ]
operations = [ operations = [
@ -29,7 +28,6 @@ class Migration(migrations.Migration):
fields=[ 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')), ('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')),
('text', models.TextField(default='')), ('text', models.TextField(default='')),
('learning_unit', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='learnpath.learningunit')),
], ],
options={ options={
'abstract': False, 'abstract': False,

View File

@ -0,0 +1,22 @@
# Generated by Django 3.2.13 on 2022-09-27 14:26
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('learnpath', '0001_initial'),
('competence', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='performancecriteria',
name='learning_unit',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='learnpath.learningunit'),
),
]

View File

@ -16,18 +16,18 @@ def create_versicherungsvermittlerin_with_categories(apps=None, schema_editor=No
course, _ = Course.objects.get_or_create( course, _ = Course.objects.get_or_create(
id=COURSE_VERSICHERUNGSVERMITTLERIN, id=COURSE_VERSICHERUNGSVERMITTLERIN,
name='Versicherungsvermittler/in', title='Versicherungsvermittler/in',
category_name='Handlungsfeld' category_name='Handlungsfeld'
) )
CourseCategory.objects.get_or_create(course=course, name='Allgemein', general=True) CourseCategory.objects.get_or_create(course=course, title='Allgemein', general=True)
for cat in [ for cat in [
'Fahrzeug', 'Reisen', 'Einkommensicherung', 'Gesundheit', 'Haushalt', 'Sparen', 'Fahrzeug', 'Reisen', 'Einkommenssicherung', 'Gesundheit', 'Haushalt', 'Sparen',
'Pensionierung', 'KMU', 'Wohneigentum', 'Rechtsstreitigkeiten', 'Erben / Vererben', 'Pensionierung', 'KMU', 'Wohneigentum', 'Rechtsstreitigkeiten', 'Erben / Vererben',
'Selbständigkeit', 'Selbständigkeit',
]: ]:
CourseCategory.objects.get_or_create(course=course, name=cat) CourseCategory.objects.get_or_create(course=course, title=cat)
# create default course page # create default course page
site = Site.objects.filter(is_default_site=True).first() site = Site.objects.filter(is_default_site=True).first()

View File

@ -8,7 +8,7 @@ class CourseFactory(DjangoModelFactory):
class Meta: class Meta:
model = Course model = Course
name = 'Versicherungsvermittler/in' title = 'Versicherungsvermittler/in'
category_name = 'Handlungsfeld' category_name = 'Handlungsfeld'

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2022-09-19 14:57 # Generated by Django 3.2.13 on 2022-09-27 14:26
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -17,7 +17,7 @@ class Migration(migrations.Migration):
name='Course', name='Course',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, verbose_name='Titel')), ('title', models.CharField(max_length=255, verbose_name='Titel')),
('category_name', models.CharField(default='Kategorie', max_length=255, verbose_name='Kategorie-Name')), ('category_name', models.CharField(default='Kategorie', max_length=255, verbose_name='Kategorie-Name')),
], ],
options={ options={
@ -39,7 +39,7 @@ class Migration(migrations.Migration):
name='CourseCategory', name='CourseCategory',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=255, verbose_name='Titel')), ('title', models.CharField(blank=True, max_length=255, verbose_name='Titel')),
('general', models.BooleanField(default=False, verbose_name='Allgemein')), ('general', models.BooleanField(default=False, verbose_name='Allgemein')),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='course.course')), ('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='course.course')),
], ],

View File

@ -7,24 +7,24 @@ from vbv_lernwelt.core.model_utils import find_available_slug
class Course(models.Model): class Course(models.Model):
name = models.CharField(_('Titel'), max_length=255) title = models.CharField(_('Titel'), max_length=255)
category_name = models.CharField(_('Kategorie-Name'), max_length=255, default='Kategorie') category_name = models.CharField(_('Kategorie-Name'), max_length=255, default='Kategorie')
class Meta: class Meta:
verbose_name = _("Lerngang") verbose_name = _("Lerngang")
def __str__(self): def __str__(self):
return f"{self.name}" return f"{self.title}"
class CourseCategory(models.Model): class CourseCategory(models.Model):
# Die Handlungsfelder im "Versicherungsvermittler/in" # Die Handlungsfelder im "Versicherungsvermittler/in"
name = models.CharField(_('Titel'), max_length=255, blank=True) title = models.CharField(_('Titel'), max_length=255, blank=True)
course = models.ForeignKey('course.Course', on_delete=models.CASCADE) course = models.ForeignKey('course.Course', on_delete=models.CASCADE)
general = models.BooleanField(_('Allgemein'), default=False) general = models.BooleanField(_('Allgemein'), default=False)
def __str__(self): def __str__(self):
return f"{self.course} / {self.name}" return f"{self.course} / {self.title}"
class CoursePage(Page): class CoursePage(Page):

View File

@ -6,10 +6,10 @@ from vbv_lernwelt.course.models import CourseCategory, Course
class CourseSerializer(serializers.ModelSerializer): class CourseSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Course model = Course
fields = ['id', 'name', 'category_name'] fields = ['id', 'title', 'category_name']
class CourseCategorySerializer(serializers.ModelSerializer): class CourseCategorySerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = CourseCategory model = CourseCategory
fields = ['id', 'name', 'general',] fields = ['id', 'title', 'general',]

View File

@ -6,7 +6,7 @@ from wagtail_localize.models import LocaleSynchronization
from vbv_lernwelt.core.admin import User from vbv_lernwelt.core.admin import User
from vbv_lernwelt.course.consts import COURSE_VERSICHERUNGSVERMITTLERIN from vbv_lernwelt.course.consts import COURSE_VERSICHERUNGSVERMITTLERIN
from vbv_lernwelt.course.models import CoursePage from vbv_lernwelt.course.models import CoursePage, CourseCategory
from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningContent, LearningUnit, \ from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningContent, LearningUnit, \
LearningUnitQuestion LearningUnitQuestion
from vbv_lernwelt.learnpath.tests.learning_path_factories import LearningPathFactory, TopicFactory, CircleFactory, \ from vbv_lernwelt.learnpath.tests.learning_path_factories import LearningPathFactory, TopicFactory, CircleFactory, \
@ -63,6 +63,7 @@ def create_circle_children(circle, title):
lu = LearningUnitFactory( lu = LearningUnitFactory(
title='Absicherung der Familie', title='Absicherung der Familie',
parent=circle, parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Einkommenssicherung')
) )
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title="Ich bin in der Lage, mit geeigneten Fragestellungen die Deckung von Versicherungen zu erfassen.", title="Ich bin in der Lage, mit geeigneten Fragestellungen die Deckung von Versicherungen zu erfassen.",
@ -122,7 +123,10 @@ def create_circle_children(circle, title):
) )
LearningSequenceFactory(title='Anwenden', parent=circle, icon='it-icon-ls-apply') LearningSequenceFactory(title='Anwenden', parent=circle, icon='it-icon-ls-apply')
lu = LearningUnitFactory(title='Prämien einsparen', parent=circle) lu = LearningUnitFactory(
title='Prämien einsparen',
parent=circle,
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title="Passende Frage zu Anwenden", title="Passende Frage zu Anwenden",
parent=lu parent=lu
@ -140,7 +144,11 @@ def create_circle_children(circle, title):
contents=[('exercise', ExerciseBlockFactory())] contents=[('exercise', ExerciseBlockFactory())]
) )
lu = LearningUnitFactory(title='Sich selbständig machen', parent=circle) lu = LearningUnitFactory(
title='Sich selbständig machen',
parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Selbständigkeit')
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title="Passende Frage zu 'Sich selbständig machen'", title="Passende Frage zu 'Sich selbständig machen'",
parent=lu parent=lu
@ -158,7 +166,11 @@ def create_circle_children(circle, title):
contents=[('exercise', ExerciseBlockFactory())] contents=[('exercise', ExerciseBlockFactory())]
) )
lu = LearningUnitFactory(title='Auto verkaufen', parent=circle) lu = LearningUnitFactory(
title='Auto verkaufen',
parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Fahrzeug')
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title='Passende Frage zu "Auto verkaufen"', title='Passende Frage zu "Auto verkaufen"',
parent=lu parent=lu
@ -188,7 +200,11 @@ def create_circle_children(circle, title):
contents=[('exercise', ExerciseBlockFactory(url='/static/media/web_based_trainings/training-04-a-01-rafael-fasel-wechselt-sein-auto-einstieg/scormcontent/index.html'))] contents=[('exercise', ExerciseBlockFactory(url='/static/media/web_based_trainings/training-04-a-01-rafael-fasel-wechselt-sein-auto-einstieg/scormcontent/index.html'))]
) )
lu = LearningUnitFactory(title='Pensionierung', parent=circle) lu = LearningUnitFactory(
title='Pensionierung',
parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Pensionierung')
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title='Passende Frage zu "Pensionierung"', title='Passende Frage zu "Pensionierung"',
parent=lu parent=lu
@ -218,7 +234,11 @@ def create_circle_children(circle, title):
contents=[('exercise', ExerciseBlockFactory())] contents=[('exercise', ExerciseBlockFactory())]
) )
lu = LearningUnitFactory(title='Reisen', parent=circle) lu = LearningUnitFactory(
title='Reisen',
parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Reisen')
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title='Passende Frage zu "Reisen"', title='Passende Frage zu "Reisen"',
parent=lu parent=lu
@ -237,7 +257,11 @@ def create_circle_children(circle, title):
url='/static/media/web_based_trainings/story-06-a-01-emma-und-ayla-campen-durch-amerika-einstieg/scormcontent/index.html'))] url='/static/media/web_based_trainings/story-06-a-01-emma-und-ayla-campen-durch-amerika-einstieg/scormcontent/index.html'))]
) )
lu = LearningUnitFactory(title='Haushalt', parent=circle) lu = LearningUnitFactory(
title='Haushalt',
parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Haushalt')
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title='Passende Frage zu "Haushalt"', title='Passende Frage zu "Haushalt"',
parent=lu parent=lu
@ -262,7 +286,11 @@ def create_circle_children(circle, title):
) )
LearningSequenceFactory(title='Üben', parent=circle, icon='it-icon-ls-practice') LearningSequenceFactory(title='Üben', parent=circle, icon='it-icon-ls-practice')
lu = LearningUnitFactory(title='Kind zieht von zu Hause aus', parent=circle) lu = LearningUnitFactory(
title='Kind zieht von zu Hause aus',
parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Einkommenssicherung')
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title='Passende Frage zu "Kind zieht von zu Hause aus"', title='Passende Frage zu "Kind zieht von zu Hause aus"',
parent=lu parent=lu
@ -287,7 +315,11 @@ def create_circle_children(circle, title):
) )
LearningSequenceFactory(title='Testen', parent=circle, icon='it-icon-ls-test') LearningSequenceFactory(title='Testen', parent=circle, icon='it-icon-ls-test')
lu = LearningUnitFactory(title='Kind zieht von zu Hause aus "Testen"', parent=circle) lu = LearningUnitFactory(
title='Kind zieht von zu Hause aus "Testen"',
parent=circle,
course_category=CourseCategory.objects.get(course_id=COURSE_VERSICHERUNGSVERMITTLERIN, title='Einkommenssicherung')
)
LearningUnitQuestionFactory( LearningUnitQuestionFactory(
title='Passende Frage zu "Kind zieht von zu Hause aus"', title='Passende Frage zu "Kind zieht von zu Hause aus"',
parent=lu parent=lu

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2022-09-19 15:05 # Generated by Django 3.2.13 on 2022-09-27 14:26
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -13,6 +13,7 @@ class Migration(migrations.Migration):
dependencies = [ dependencies = [
('wagtailcore', '0069_log_entry_jsonfield'), ('wagtailcore', '0069_log_entry_jsonfield'),
('course', '0001_initial'),
] ]
operations = [ operations = [
@ -35,7 +36,7 @@ class Migration(migrations.Migration):
fields=[ 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')), ('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)), ('minutes', models.PositiveIntegerField(default=15)),
('contents', wagtail.fields.StreamField([('video', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('web_based_training', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('podcast', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('competence', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock())])), ('exercise', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('document', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock())])), ('knowledge', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock())]))], use_json_field=None)), ('contents', wagtail.fields.StreamField([('video', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('resource', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('exercise', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('online_training', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('media_library', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('document', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('test', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('book', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('assignment', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())]))], use_json_field=None)),
], ],
options={ options={
'verbose_name': 'Learning Content', 'verbose_name': 'Learning Content',
@ -63,16 +64,6 @@ class Migration(migrations.Migration):
}, },
bases=('wagtailcore.page',), bases=('wagtailcore.page',),
), ),
migrations.CreateModel(
name='LearningUnit',
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')),
],
options={
'verbose_name': 'Learning Unit',
},
bases=('wagtailcore.page',),
),
migrations.CreateModel( migrations.CreateModel(
name='LearningUnitQuestion', name='LearningUnitQuestion',
fields=[ fields=[
@ -94,4 +85,15 @@ class Migration(migrations.Migration):
}, },
bases=('wagtailcore.page',), bases=('wagtailcore.page',),
), ),
migrations.CreateModel(
name='LearningUnit',
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')),
('course_category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='course.coursecategory')),
],
options={
'verbose_name': 'Learning Unit',
},
bases=('wagtailcore.page',),
),
] ]

View File

@ -1,20 +0,0 @@
# Generated by Django 3.2.13 on 2022-09-27 13:54
from django.db import migrations
import wagtail.blocks
import wagtail.fields
class Migration(migrations.Migration):
dependencies = [
('learnpath', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='learningcontent',
name='contents',
field=wagtail.fields.StreamField([('video', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('resource', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('exercise', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('online_training', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('media_library', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('document', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('test', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('book', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())])), ('assignment', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock()), ('url', wagtail.blocks.URLBlock())]))], use_json_field=None),
),
]

View File

@ -8,6 +8,7 @@ from wagtail.images.blocks import ImageChooserBlock
from wagtail.models import Page from wagtail.models import Page
from vbv_lernwelt.core.model_utils import find_available_slug from vbv_lernwelt.core.model_utils import find_available_slug
from vbv_lernwelt.course.models import CoursePage
from vbv_lernwelt.learnpath.models_learning_unit_content import VideoBlock, \ from vbv_lernwelt.learnpath.models_learning_unit_content import VideoBlock, \
ExerciseBlock, DocumentBlock, AssignmentBlock, BookBlock, MediaLibraryBlock, \ ExerciseBlock, DocumentBlock, AssignmentBlock, BookBlock, MediaLibraryBlock, \
OnlineTrainingBlock, ResourceBlock, TestBlock OnlineTrainingBlock, ResourceBlock, TestBlock
@ -165,6 +166,11 @@ class LearningSequence(Page):
class LearningUnit(Page): class LearningUnit(Page):
parent_page_types = ['learnpath.Circle'] parent_page_types = ['learnpath.Circle']
subpage_types = [] subpage_types = []
course_category = models.ForeignKey('course.CourseCategory', on_delete=models.SET_NULL, null=True, blank=True)
content_panels = Page.content_panels + [
FieldPanel('course_category'),
]
class Meta: class Meta:
verbose_name = "Learning Unit" verbose_name = "Learning Unit"
@ -173,7 +179,18 @@ class LearningUnit(Page):
return f"{self.title}" return f"{self.title}"
def full_clean(self, *args, **kwargs): def full_clean(self, *args, **kwargs):
self.slug = find_slug_with_parent_prefix(self, 'lu') course = None
course_parent_page = self.get_ancestors().exact_type(CoursePage).last()
if course_parent_page:
course = course_parent_page.specific.course
if self.course_category is None and course:
self.course_category = course.coursecategory_set.filter(general=True).first()
if self.course_category.general:
self.slug = find_slug_with_parent_prefix(self, 'lu')
else:
self.slug = find_slug_with_parent_prefix(self, 'lu', self.course_category.title)
super(LearningUnit, self).full_clean(*args, **kwargs) super(LearningUnit, self).full_clean(*args, **kwargs)
@classmethod @classmethod
@ -265,11 +282,14 @@ class LearningContent(Page):
return f"{self.title}" return f"{self.title}"
def find_slug_with_parent_prefix(page, type_prefix): def find_slug_with_parent_prefix(page, type_prefix, slug_postfix=None):
parent_slug = page.get_ancestors().exact_type(LearningPath, Circle).last().slug parent_slug = page.get_ancestors().exact_type(LearningPath, Circle).last().slug
if parent_slug: if parent_slug:
slug_prefix = f"{parent_slug}-{type_prefix}" slug_prefix = f"{parent_slug}-{type_prefix}"
else: else:
slug_prefix = type_prefix slug_prefix = type_prefix
return find_available_slug(slugify(f'{slug_prefix}-{page.title}', allow_unicode=True)) if slug_postfix is None:
slug_postfix = page.title
return find_available_slug(slugify(f'{slug_prefix}-{slug_postfix}', allow_unicode=True))

View File

@ -14,9 +14,9 @@ def create_default_collections():
root, created = Collection.objects.get_or_create(name='Root', depth=0) root, created = Collection.objects.get_or_create(name='Root', depth=0)
for course in Course.objects.all(): for course in Course.objects.all():
course_collection = root.add_child(name=course.name) course_collection = root.add_child(name=course.title)
for cat in course.coursecategory_set.all(): for cat in course.coursecategory_set.all():
cat_collection = course_collection.add_child(name=cat.name) cat_collection = course_collection.add_child(name=cat.title)
def create_default_documents(): def create_default_documents():

View File

@ -43,7 +43,7 @@ welche Aspekte du bei einer Offerte beachten musst und wie du dem Kunden die Lö
]) ])
media_category = MediaCategoryPageFactory( media_category = MediaCategoryPageFactory(
overview_icon=overview_icon, overview_icon=overview_icon,
title=cat.name, title=cat.title,
course_category=cat, course_category=cat,
parent=media_lib_page, parent=media_lib_page,
introduction_text=introduction_text, introduction_text=introduction_text,

View File

@ -1,16 +1,15 @@
# Generated by Django 3.2.13 on 2022-09-23 15:27 # Generated by Django 3.2.13 on 2022-09-27 14:26
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import taggit.managers import taggit.managers
import vbv_lernwelt.media_library.content_blocks
import wagtail.blocks import wagtail.blocks
import wagtail.documents.blocks import wagtail.documents.blocks
import wagtail.fields import wagtail.fields
import wagtail.models.collections import wagtail.models.collections
import wagtail.search.index import wagtail.search.index
from django.conf import settings
from django.db import migrations, models
import vbv_lernwelt.media_library.content_blocks
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -18,10 +17,10 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('wagtailcore', '0069_log_entry_jsonfield'),
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
('course', '0001_initial'), ('course', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('wagtailcore', '0069_log_entry_jsonfield'),
('taggit', '0004_alter_taggeditem_content_type_alter_taggeditem_tag'),
] ]
operations = [ operations = [
@ -54,7 +53,7 @@ class Migration(migrations.Migration):
('items', wagtail.fields.StreamField([('item', wagtail.blocks.TextBlock())], use_json_field=True)), ('items', wagtail.fields.StreamField([('item', wagtail.blocks.TextBlock())], use_json_field=True)),
('overview_icon', models.CharField(default='icon-hf-fahrzeug', max_length=255)), ('overview_icon', models.CharField(default='icon-hf-fahrzeug', max_length=255)),
('body', wagtail.fields.StreamField([('content_collection', wagtail.blocks.StructBlock([('title', wagtail.blocks.TextBlock()), ('contents', wagtail.blocks.StreamBlock([('Links', wagtail.blocks.StructBlock([('title', wagtail.blocks.TextBlock(blank=False, null=False)), ('description', wagtail.blocks.TextBlock(default='')), ('link_display_text', wagtail.blocks.CharBlock(default='Link öffnen', max_length=255)), ('url', wagtail.blocks.URLBlock())])), ('Documents', wagtail.documents.blocks.DocumentChooserBlock()), ('Ankers', vbv_lernwelt.media_library.content_blocks.AnchorBlock()), ('CrossReference', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock(default='')), ('link_display_text', wagtail.blocks.CharBlock(default='Link öffnen', max_length=255)), ('category', wagtail.blocks.PageChooserBlock(page_type=['media_library.MediaCategoryPage']))]))]))]))], null=True, use_json_field=True)), ('body', wagtail.fields.StreamField([('content_collection', wagtail.blocks.StructBlock([('title', wagtail.blocks.TextBlock()), ('contents', wagtail.blocks.StreamBlock([('Links', wagtail.blocks.StructBlock([('title', wagtail.blocks.TextBlock(blank=False, null=False)), ('description', wagtail.blocks.TextBlock(default='')), ('link_display_text', wagtail.blocks.CharBlock(default='Link öffnen', max_length=255)), ('url', wagtail.blocks.URLBlock())])), ('Documents', wagtail.documents.blocks.DocumentChooserBlock()), ('Ankers', vbv_lernwelt.media_library.content_blocks.AnchorBlock()), ('CrossReference', wagtail.blocks.StructBlock([('description', wagtail.blocks.TextBlock(default='')), ('link_display_text', wagtail.blocks.CharBlock(default='Link öffnen', max_length=255)), ('category', wagtail.blocks.PageChooserBlock(page_type=['media_library.MediaCategoryPage']))]))]))]))], null=True, use_json_field=True)),
('course_category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='course.coursecategory')), ('course_category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='course.coursecategory')),
], ],
options={ options={
'abstract': False, 'abstract': False,

View File

@ -38,7 +38,7 @@ class MediaCategoryPage(Page):
""" """
Handlungsfeld. zB. Fahrzeug Handlungsfeld. zB. Fahrzeug
""" """
course_category = models.ForeignKey('course.CourseCategory', on_delete=models.CASCADE) course_category = models.ForeignKey('course.CourseCategory', on_delete=models.SET_NULL, null=True, blank=True)
parent_page_types = ['media_library.MediaLibraryPage'] parent_page_types = ['media_library.MediaLibraryPage']
introduction_text = models.TextField(default='') introduction_text = models.TextField(default='')
description_title = models.TextField(default='Das erwartet dich in diesem Handlungsfeld') description_title = models.TextField(default='Das erwartet dich in diesem Handlungsfeld')