diff --git a/client/src/gql/schema.graphql b/client/src/gql/schema.graphql index bda09a38..53a7aeb7 100644 --- a/client/src/gql/schema.graphql +++ b/client/src/gql/schema.graphql @@ -335,7 +335,7 @@ type CircleLightObjectType { type CourseSessionUserType { id: UUID! - chosen_profile: String + chosen_profile: String! course_session: CourseSessionObjectType! } @@ -720,6 +720,7 @@ type TopicObjectType implements CoursePageInterface { type CircleObjectType implements CoursePageInterface { description: String! goals: String! + is_base_circle: Boolean! id: ID! title: String! slug: String! diff --git a/server/vbv_lernwelt/course/management/commands/create_default_courses.py b/server/vbv_lernwelt/course/management/commands/create_default_courses.py index 2798f21e..2dbfafc6 100644 --- a/server/vbv_lernwelt/course/management/commands/create_default_courses.py +++ b/server/vbv_lernwelt/course/management/commands/create_default_courses.py @@ -3,7 +3,7 @@ import random from datetime import datetime, timedelta import djclick as click -from dateutil.relativedelta import MO, relativedelta, TH, TU +from dateutil.relativedelta import MO, TH, TU, relativedelta from django.utils import timezone from vbv_lernwelt.assignment.creators.create_assignments import ( @@ -101,6 +101,7 @@ from vbv_lernwelt.learnpath.create_vv_new_learning_path import ( create_vv_new_learning_path, create_vv_pruefung_learning_path, ) +from vbv_lernwelt.learnpath.creators import assign_circles_to_profiles from vbv_lernwelt.learnpath.models import ( Circle, LearningContent, @@ -222,6 +223,7 @@ def create_versicherungsvermittlerin_course( create_vv_gewinnen_casework(course_id=course_id) create_vv_reflection(course_id=course_id) create_vv_new_learning_path(course_id=course_id) + assign_circles_to_profiles() cs = CourseSession.objects.create(course_id=course_id, title=names[language]) diff --git a/server/vbv_lernwelt/learnpath/creators.py b/server/vbv_lernwelt/learnpath/creators.py index 14dca7c3..e94806c5 100644 --- a/server/vbv_lernwelt/learnpath/creators.py +++ b/server/vbv_lernwelt/learnpath/creators.py @@ -1,3 +1,6 @@ +import structlog + +from vbv_lernwelt.course.consts import COURSE_VERSICHERUNGSVERMITTLERIN_ID from vbv_lernwelt.learnpath.consts import ( COURSE_PROFILE_KRANKENZUSATZ_CODE, COURSE_PROFILE_KRANKENZUSATZ_ID, @@ -7,6 +10,8 @@ from vbv_lernwelt.learnpath.consts import ( COURSE_PROFILE_NICHTLEBEN_ID, ) +logger = structlog.get_logger(__name__) + def create_course_profiles(): from vbv_lernwelt.learnpath.models import CourseProfile @@ -20,3 +25,53 @@ def create_course_profiles(): CourseProfile.objects.create( id=COURSE_PROFILE_KRANKENZUSATZ_ID, code=COURSE_PROFILE_KRANKENZUSATZ_CODE ) + + +def assign_circles_to_profiles(): + from vbv_lernwelt.course.models import CoursePage + from vbv_lernwelt.learnpath.models import Circle, CourseProfile + + try: + course_page = CoursePage.objects.get( + course_id=COURSE_VERSICHERUNGSVERMITTLERIN_ID + ) + except CoursePage.DoesNotExist: + logger.warning("Course does not exist yet") + return + + def assign_circle_to_profile(title, code): + try: + circle = Circle.objects.descendant_of(course_page).get(title=title) + course_profile = CourseProfile.objects.get(code=code) + circle.profiles.add(course_profile) + circle.save() + except Circle.DoesNotExist: + logger.warning("assign_circle_to_profile: circle not found", title=title) + + def make_base_circle(title): + try: + circle = Circle.objects.descendant_of(course_page).get(title=title) + circle.is_base_circle = True + circle.save() + except Circle.DoesNotExist: + logger.warning("assign_circle_to_profile: circle not found", title=title) + + assign_circle_to_profile("Fahrzeug", COURSE_PROFILE_NICHTLEBEN_CODE) + assign_circle_to_profile("Haushalt", COURSE_PROFILE_NICHTLEBEN_CODE) + assign_circle_to_profile("Rechtsstreitigkeiten", COURSE_PROFILE_NICHTLEBEN_CODE) + assign_circle_to_profile("Reisen", COURSE_PROFILE_NICHTLEBEN_CODE) + assign_circle_to_profile("Wohneigentum", COURSE_PROFILE_NICHTLEBEN_CODE) + assign_circle_to_profile("Selbständigkeit", COURSE_PROFILE_NICHTLEBEN_CODE) + assign_circle_to_profile("KMU", COURSE_PROFILE_NICHTLEBEN_CODE) + + assign_circle_to_profile("Einkommenssicherung", COURSE_PROFILE_LEBEN_CODE) + assign_circle_to_profile("Pensionierung", COURSE_PROFILE_LEBEN_CODE) + assign_circle_to_profile("Erben/Vererben", COURSE_PROFILE_LEBEN_CODE) + assign_circle_to_profile("Sparen", COURSE_PROFILE_LEBEN_CODE) + assign_circle_to_profile("Selbständigkeit", COURSE_PROFILE_LEBEN_CODE) + assign_circle_to_profile("KMU", COURSE_PROFILE_LEBEN_CODE) + + assign_circle_to_profile("Gesundheit", COURSE_PROFILE_KRANKENZUSATZ_CODE) + + make_base_circle("Basis") + make_base_circle("Gewinnen") diff --git a/server/vbv_lernwelt/learnpath/graphql/types.py b/server/vbv_lernwelt/learnpath/graphql/types.py index cfbd11d7..7d29e5fd 100644 --- a/server/vbv_lernwelt/learnpath/graphql/types.py +++ b/server/vbv_lernwelt/learnpath/graphql/types.py @@ -307,7 +307,7 @@ class CircleObjectType(DjangoObjectType): class Meta: model = Circle interfaces = (CoursePageInterface,) - fields = ["description", "goals"] + fields = ["description", "goals", "is_base_circle"] def resolve_learning_sequences(self: Circle, info, **kwargs): circle_descendants = None @@ -336,10 +336,9 @@ class CircleObjectType(DjangoObjectType): if descendant.specific_class == LearningSequence ] - def resolve_profiles(self, info, **kwargs): - # choices = ["life", "nonlife", "sick"] - choices = CourseProfile.objects.all() - return [random.choice(choices).code] + @staticmethod + def resolve_profiles(root: Circle, info, **kwargs): + return root.profiles.all() class TopicObjectType(DjangoObjectType):