diff --git a/client/src/router/index.ts b/client/src/router/index.ts index f821c851..d53348aa 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -25,6 +25,11 @@ const router = createRouter({ meta: { public: true } + }, + { + path: '/learningpath/:learningPathSlug', + component: () => import('../views/LearningPathView.vue'), + props: true }, { path: '/circle/:circleSlug', diff --git a/client/src/views/HomeView.vue b/client/src/views/HomeView.vue index 7fb5eee8..7bda4a1c 100644 --- a/client/src/views/HomeView.vue +++ b/client/src/views/HomeView.vue @@ -10,6 +10,7 @@ import MainNavigationBar from '@/components/MainNavigationBar.vue';
Styelguide Login + Lernpfad "Versicherungsvermittlerin" (Login benötigt) Circle "Analyse" (Login benötigt)
diff --git a/client/src/views/LearningPathView.vue b/client/src/views/LearningPathView.vue new file mode 100644 index 00000000..59f53dad --- /dev/null +++ b/client/src/views/LearningPathView.vue @@ -0,0 +1,84 @@ + + + + + diff --git a/server/vbv_lernwelt/learnpath/models.py b/server/vbv_lernwelt/learnpath/models.py index 326e6ebc..a8e12cfd 100644 --- a/server/vbv_lernwelt/learnpath/models.py +++ b/server/vbv_lernwelt/learnpath/models.py @@ -95,6 +95,11 @@ class Circle(Page): APIField('description'), ] + + @classmethod + def get_serializer_class(cls): + return get_it_serializer_class(cls, field_names=['id', 'title', 'slug', 'type', 'translation_key']) + def full_clean(self, *args, **kwargs): # self.slug = find_available_slug(Circle, slugify(self.title, allow_unicode=True)) super(Circle, self).full_clean(*args, **kwargs) diff --git a/server/vbv_lernwelt/learnpath/serializers.py b/server/vbv_lernwelt/learnpath/serializers.py index 0e2201af..70dde5b5 100644 --- a/server/vbv_lernwelt/learnpath/serializers.py +++ b/server/vbv_lernwelt/learnpath/serializers.py @@ -1,6 +1,6 @@ from rest_framework import serializers -from vbv_lernwelt.learnpath.models import Circle +from vbv_lernwelt.learnpath.models import Circle, LearningPath from vbv_lernwelt.learnpath.serializer_helpers import get_it_serializer_class @@ -18,3 +18,19 @@ class CircleSerializer(get_it_serializer_class(Circle, [])): class Meta: model = Circle fields = ['id', 'title', 'slug', 'children', 'type'] + + +class LearningPathSerializer(get_it_serializer_class(LearningPath, [])): + children = serializers.SerializerMethodField() + + meta_fields = [] + + def get_children(self, obj): + return [c.specific.get_serializer_class()(c.specific).data for c in obj.get_children()] + + def get_meta_label(self, obj): + return obj._meta.label + + class Meta: + model = Circle + fields = ['id', 'title', 'slug', 'children', 'type'] diff --git a/server/vbv_lernwelt/learnpath/tests/bla.json b/server/vbv_lernwelt/learnpath/tests/bla.json new file mode 100644 index 00000000..b6db424b --- /dev/null +++ b/server/vbv_lernwelt/learnpath/tests/bla.json @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# +# Iterativ GmbH +# http://www.iterativ.ch/ +# +# Copyright (c) 2015 Iterativ GmbH. All rights reserved. +# +# Created on 2022-06-07 +# @author: lorenz.padberg@iterativ.ch diff --git a/server/vbv_lernwelt/learnpath/urls.py b/server/vbv_lernwelt/learnpath/urls.py index 2bae3734..ed8aa366 100644 --- a/server/vbv_lernwelt/learnpath/urls.py +++ b/server/vbv_lernwelt/learnpath/urls.py @@ -3,8 +3,9 @@ from django.urls import path from rest_framework.routers import DefaultRouter from . import views -from .views import circle_view +from .views import circle_view, learningpath_view urlpatterns = [ path(r"api/circle//", circle_view, name="circle_view"), + path(r"api/learningpath//", learningpath_view, name="learningpath_view"), ] diff --git a/server/vbv_lernwelt/learnpath/views.py b/server/vbv_lernwelt/learnpath/views.py index 4607a9d3..7b700921 100644 --- a/server/vbv_lernwelt/learnpath/views.py +++ b/server/vbv_lernwelt/learnpath/views.py @@ -2,8 +2,8 @@ from rest_framework.decorators import api_view from rest_framework.response import Response -from vbv_lernwelt.learnpath.models import Circle -from vbv_lernwelt.learnpath.serializers import CircleSerializer +from vbv_lernwelt.learnpath.models import Circle, LearningPath +from vbv_lernwelt.learnpath.serializers import CircleSerializer, LearningPathSerializer @api_view(['GET']) @@ -11,3 +11,10 @@ def circle_view(request, slug): circle = Circle.objects.get(slug=slug) serializer = CircleSerializer(circle) return Response(serializer.data) + + +@api_view(['GET']) +def learningpath_view(request, slug): + learning_path = LearningPath.objects.get(slug=slug) + serializer = LearningPathSerializer(learning_path) + return Response(serializer.data)