diff --git a/server/vbv_lernwelt/learnpath/migrations/0005_learningunit_contents.py b/server/vbv_lernwelt/learnpath/migrations/0005_learningunit_contents.py new file mode 100644 index 00000000..b1a2ffa9 --- /dev/null +++ b/server/vbv_lernwelt/learnpath/migrations/0005_learningunit_contents.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.12 on 2022-04-19 09:37 + +from django.db import migrations +import wagtail.core.blocks +import wagtail.core.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('learnpath', '0004_auto_20220414_1503'), + ] + + operations = [ + migrations.AddField( + model_name='learningunit', + name='contents', + field=wagtail.core.fields.StreamField([('web_based_training', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('video', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())]))], blank=True, null=True), + ), + ] diff --git a/server/vbv_lernwelt/learnpath/models.py b/server/vbv_lernwelt/learnpath/models.py index 3c6a2080..732d04f2 100644 --- a/server/vbv_lernwelt/learnpath/models.py +++ b/server/vbv_lernwelt/learnpath/models.py @@ -1,17 +1,12 @@ # Create your models here. from django.db import models -from wagtail.admin.edit_handlers import FieldPanel +from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel +from wagtail.core.blocks import StreamBlock +from wagtail.core.fields import StreamField from wagtail.core.models import Page -from django.utils.translation import gettext_lazy as _ - -# class HomePage(Page): -# body = RichTextField(default='', blank=True) -# -# content_panels = Page.content_panels + [ -# FieldPanel('body', classname="full"), -# ] +from vbv_lernwelt.learnpath.models_learning_unit_content import WebBasedTrainingBlock, VideoBlock class LearningPath(Page): @@ -90,7 +85,23 @@ class LearningSequence(Page): class LearningUnit(Page): - parent_page_types = ['learnpath.Circle'] + # 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" diff --git a/server/vbv_lernwelt/learnpath/models_learning_unit_content.py b/server/vbv_lernwelt/learnpath/models_learning_unit_content.py new file mode 100644 index 00000000..9e14e920 --- /dev/null +++ b/server/vbv_lernwelt/learnpath/models_learning_unit_content.py @@ -0,0 +1,33 @@ +from django.db import models +from wagtail.core import blocks + + +# 'video_block' +class VideoBlock(blocks.StructBlock): + # TODO: Possible video Types for the user, upload file, add URL + title = models.CharField(max_length=128, default="") + description = models.TextField(default="") + url = blocks.URLBlock() + + class Meta: + icon = 'media' + + + +# 'Web based training Block' +class WebBasedTrainingBlock(blocks.StructBlock): + RISE = 'rise' + + WBT_TYPE_CHOICES = ( + (RISE, 'Rise'), + ) + + url = blocks.URLBlock() + type = models.CharField( + max_length=100, + choices=WBT_TYPE_CHOICES, + default=RISE + ) + + class Meta: + icon = 'media' diff --git a/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py b/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py index 8de92408..81a2c1db 100644 --- a/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py +++ b/server/vbv_lernwelt/learnpath/tests/create_default_learning_path.py @@ -3,14 +3,14 @@ from wagtail.core.models import Site from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningUnit from vbv_lernwelt.learnpath.tests.learningpath_factories import LearningPathFactory, TopicFactory, CircleFactory, \ - LearningSequenceFactory, LearningUnitFactory + LearningSequenceFactory, LearningUnitFactory, VideoBlockFactory, WebBasedTrainingBlockFactory def create_default_learning_path(): site = Site.objects.filter(is_default_site=True).first() if not site: - site = wagtail_factories.SiteFactory.get(is_default_site=True) + site = wagtail_factories.SiteFactory(is_default_site=True) lp = LearningPathFactory.create(title="Versicherungsvermittler/in", parent=site.root_page) @@ -61,6 +61,21 @@ von Neukunden zu benützen sequence_1 = LearningSequenceFactory.create(title="Starten", parent=circle_4) learning_unit = LearningUnitFactory.create(title='Einleitung Circle "Anlayse"', parent=sequence_1) + + learning_unit = LearningUnitFactory.create(title='** Einstieg Video"', parent=sequence_1) + video_url = "https://www.vbv.ch/fileadmin/vbv/Videos/Statements_Externe/Janos_M/Testimonial_Janos_Mischler_PositiveEffekte.mp4" + video_title = "Ausbildung ist pflicht" + video_description = "Erfahren Sie, was für Janos Mischler die positiven Aspekte von ständiger Weiterbildung sind – aus fachlicher und aus persönlicher Sicht." + video_block = VideoBlockFactory(type="video", url=video_url, title=video_title, description=video_description) + learning_unit.contents.append(('video', video_block)) + learning_unit.save() + + learning_unit = LearningUnitFactory.create(title='** Web Based Training"', parent=sequence_1) + wbt_url = "web_based_trainings/rise_cmi5_test_export/scormcontent/index.html" + wbt_block = WebBasedTrainingBlockFactory(type="web_based_training", url=wbt_url) + learning_unit.contents.append(('web_based_training', wbt_block)) + learning_unit.save() + learning_unit = LearningUnitFactory.create(title="Selbsteinschätzung", parent=sequence_1) sequence_2 = LearningSequenceFactory.create(title="Beobachten", parent=circle_4) diff --git a/server/vbv_lernwelt/learnpath/tests/learningpath_factories.py b/server/vbv_lernwelt/learnpath/tests/learningpath_factories.py index b13d7dc7..02f93bfc 100644 --- a/server/vbv_lernwelt/learnpath/tests/learningpath_factories.py +++ b/server/vbv_lernwelt/learnpath/tests/learningpath_factories.py @@ -1,6 +1,7 @@ import wagtail_factories from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningUnit +from vbv_lernwelt.learnpath.models_learning_unit_content import VideoBlock, WebBasedTrainingBlock class LearningPathFactory(wagtail_factories.PageFactory): @@ -37,3 +38,19 @@ class LearningUnitFactory(wagtail_factories.PageFactory): class Meta: model = LearningUnit + + +class VideoBlockFactory(wagtail_factories.StructBlockFactory): + title = "Ausbildung ist Pflicht" + url = "https://www.vbv.ch/fileadmin/vbv/Videos/Statements_Externe/Janos_M/Testimonial_Janos_Mischler_PositiveEffekte.mp4" + + class Meta: + model = VideoBlock + +class WebBasedTrainingBlockFactory(wagtail_factories.StructBlockFactory): + title = "Beispiel Rise Modul" + url = "https://docs.wagtail.org/en/stable/topics/streamfield.html" + + class Meta: + model = WebBasedTrainingBlock + diff --git a/server/vbv_lernwelt/learnpath/tests/test_create_default_learning_path.py b/server/vbv_lernwelt/learnpath/tests/test_create_default_learning_path.py index c7fafd50..bbe0be8f 100644 --- a/server/vbv_lernwelt/learnpath/tests/test_create_default_learning_path.py +++ b/server/vbv_lernwelt/learnpath/tests/test_create_default_learning_path.py @@ -18,4 +18,4 @@ class TestCreateDefaultLearningPaths(TestCase): def create_locales_for_wagtail(): for language in settings.WAGTAIL_CONTENT_LANGUAGES: - Locale.objects.create(language_code=language[0]) + Locale.objects.get_or_create(language_code=language[0]) diff --git a/server/vbv_lernwelt/templates/learnpath/circle.html b/server/vbv_lernwelt/templates/learnpath/circle.html index f37753f5..2e5e09c3 100644 --- a/server/vbv_lernwelt/templates/learnpath/circle.html +++ b/server/vbv_lernwelt/templates/learnpath/circle.html @@ -36,7 +36,7 @@