diff --git a/server/vbv_lernwelt/learnpath/management/commands/create_default_learning_path.py b/server/vbv_lernwelt/learnpath/management/commands/create_default_learning_path.py index 0dd5d605..13ef5e61 100644 --- a/server/vbv_lernwelt/learnpath/management/commands/create_default_learning_path.py +++ b/server/vbv_lernwelt/learnpath/management/commands/create_default_learning_path.py @@ -6,3 +6,4 @@ from vbv_lernwelt.learnpath.tests.create_default_learning_path import create_def @click.command() def command(): create_default_learning_path(skip_locales=True) + # create_simple_test_learning_path(skip_locales=True) diff --git a/server/vbv_lernwelt/learnpath/tests/create_simple_test_learning_path.py b/server/vbv_lernwelt/learnpath/tests/create_simple_test_learning_path.py new file mode 100644 index 00000000..f3c8c153 --- /dev/null +++ b/server/vbv_lernwelt/learnpath/tests/create_simple_test_learning_path.py @@ -0,0 +1,149 @@ +import wagtail_factories +from django.conf import settings +from wagtail.models import Site, Page + +from vbv_lernwelt.core.admin import User +from vbv_lernwelt.learnpath.tests.learning_path_factories import LearningPathFactory, TopicFactory, CircleFactory, \ + LearningSequenceFactory, LearningContentFactory, VideoBlockFactory, PodcastBlockFactory, CompetenceBlockFactory, \ + ExerciseBlockFactory, LearningUnitFactory, LearningUnitQuestionFactory + + +def create_circle(title, learning_path): + return CircleFactory( + title=title, + parent=learning_path, + description="Unit-Test Circle", + job_situations=[ + ('job_situation', 'Absicherung der Familie'), + ('job_situation', 'Reisen'), + ], + goals=[ + ('goal', '... die heutige Versicherungssituation von Privat- oder Geschäftskunden einzuschätzen.'), + ('goal', '... deinem Kunden seine optimale Lösung aufzuzeigen'), + ], + experts=[ + ('person', {'last_name': 'Huggel', 'first_name': 'Patrizia', 'email': 'patrizia.huggel@example.com'}), + ] + ) + + +def create_circle_children(circle, title): + LearningSequenceFactory(title='Starten', parent=circle, icon='it-icon-ls-start') + LearningContentFactory( + title=f'Einleitung Circle "{title}"', + parent=circle, + minutes=15, + contents=[('video', VideoBlockFactory( + url='https://www.youtube.com/embed/qhPIfxS2hvI', + description='In dieser Circle zeigt dir ein Fachexperte anhand von Kundensituationen, wie du erfolgreich' + 'den Kundenbedarf ermitteln, analysieren, priorisieren und anschliessend zusammenfassen kannst.' + ))] + ) + + LearningSequenceFactory(title='Beobachten', parent=circle, icon='it-icon-ls-watch') + lu = LearningUnitFactory( + title='Absicherung der Familie', + parent=circle, + ) + LearningUnitQuestionFactory( + title="Ich bin in der Lage, mit geeigneten Fragestellungen die Deckung von Versicherungen zu erfassen.", + parent=lu + ) + LearningUnitQuestionFactory( + title="Zweite passende Frage zu 'Absicherung der Familie'", + parent=lu + ) + LearningContentFactory( + title='Ermittlung des Kundenbedarfs', + parent=circle, + minutes=30, + contents=[('podcast', PodcastBlockFactory( + description='Die Ermittlung des Kundenbedarfs muss in einem eingehenden Gespräch herausgefunden werden. Höre dazu auch diesen Podcast an.', + url='https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/325190984&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true', + ))] + ) + LearningContentFactory( + title='Kundenbedürfnisse erkennen', + parent=circle, + minutes=30, + contents=[('competence', CompetenceBlockFactory())] + ) + LearningContentFactory( + title='Was braucht eine Familie?', + parent=circle, + minutes=60, + contents=[('exercise', ExerciseBlockFactory(url='/media/web_based_trainings/story-01-a-01-patrizia-marco-sichern-sich-ab-einstieg/scormcontent/index.html' + ))] + + ) + + lu = LearningUnitFactory(title='Reisen', parent=circle) + LearningUnitQuestionFactory( + title='Passende Frage zu "Reisen"', + parent=lu + ) + LearningContentFactory( + title='Reiseversicherung', + parent=circle, + minutes=240, + contents=[('competence', CompetenceBlockFactory())] + ) + LearningContentFactory( + title='Sorgenfrei reisen', + parent=circle, + minutes=120, + contents=[('exercise', ExerciseBlockFactory( + url='/media/web_based_trainings/story-06-a-01-emma-und-ayla-campen-durch-amerika-einstieg/scormcontent/index.html'))] + ) + + LearningSequenceFactory(title='Beenden', parent=circle, icon='it-icon-ls-end') + LearningContentFactory( + title='Kompetenzprofil anschauen', + parent=circle, + minutes=30, + contents=[('document', CompetenceBlockFactory())] + ) + LearningContentFactory( + title='Circle "Analyse" abschliessen', + parent=circle, + minutes=30, + contents=[('document', CompetenceBlockFactory())] + ) + + +def create_simple_test_learning_path(user=None, skip_locales=True): + if user is None: + user = User.objects.get(username='info@iterativ.ch') + + site = Site.objects.filter(is_default_site=True).first() + + if not site: + site = wagtail_factories.SiteFactory(is_default_site=True) + + if settings.APP_ENVIRONMENT == 'development': + site.port = 8000 + site.save() + + lp = LearningPathFactory(title="Unit-Test Lernpfad", parent=site.root_page) + TopicFactory(title="Unit-Test Topic", is_visible=False, parent=lp) + + circle_analyse = create_circle('Unit-Test Circle', lp) + create_circle_children(circle_analyse, 'Unit-Test Circle') + + # locales + # if not skip_locales: + # locale_de = Locale.objects.get(language_code='de-CH') + # locale_fr, _ = Locale.objects.get_or_create(language_code='fr-CH') + # LocaleSynchronization.objects.get_or_create( + # locale_id=locale_fr.id, + # sync_from_id=locale_de.id + # ) + # locale_it, _ = Locale.objects.get_or_create(language_code='it-CH') + # LocaleSynchronization.objects.get_or_create( + # locale_id=locale_it.id, + # sync_from_id=locale_de.id + # ) + # call_command('sync_locale_trees') + + # all pages belong to 'admin' by default + Page.objects.update(owner=user) diff --git a/server/vbv_lernwelt/learnpath/views.py b/server/vbv_lernwelt/learnpath/views.py index c1ea8f26..590bbd66 100644 --- a/server/vbv_lernwelt/learnpath/views.py +++ b/server/vbv_lernwelt/learnpath/views.py @@ -2,6 +2,7 @@ import glob from pathlib import Path +import structlog from django.conf import settings from django.shortcuts import render from django.views.decorators.cache import cache_page @@ -11,13 +12,19 @@ from wagtail.models import Page from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt +logger = structlog.get_logger(__name__) + @api_view(['GET']) @cache_page(60 * 60 * 8, cache="learning_path_cache") def page_api_view(request, slug): - page = Page.objects.get(slug=slug, locale__language_code='de-CH') - serializer = page.specific.get_serializer_class()(page.specific) - return Response(serializer.data) + try: + page = Page.objects.get(slug=slug, locale__language_code='de-CH') + serializer = page.specific.get_serializer_class()(page.specific) + return Response(serializer.data) + except Exception as e: + logger.error(e) + return Response({"error": str(e)}, status=404) @django_view_authentication_exempt