Add course profile and circle data as migration and also inside django

command
This commit is contained in:
Ramon Wenger 2024-07-11 17:44:03 +02:00 committed by Christian Cueni
parent 208fa3c8b9
commit f5fe285986
4 changed files with 64 additions and 7 deletions

View File

@ -335,7 +335,7 @@ type CircleLightObjectType {
type CourseSessionUserType { type CourseSessionUserType {
id: UUID! id: UUID!
chosen_profile: String chosen_profile: String!
course_session: CourseSessionObjectType! course_session: CourseSessionObjectType!
} }
@ -720,6 +720,7 @@ type TopicObjectType implements CoursePageInterface {
type CircleObjectType implements CoursePageInterface { type CircleObjectType implements CoursePageInterface {
description: String! description: String!
goals: String! goals: String!
is_base_circle: Boolean!
id: ID! id: ID!
title: String! title: String!
slug: String! slug: String!

View File

@ -3,7 +3,7 @@ import random
from datetime import datetime, timedelta from datetime import datetime, timedelta
import djclick as click 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 django.utils import timezone
from vbv_lernwelt.assignment.creators.create_assignments import ( 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_new_learning_path,
create_vv_pruefung_learning_path, create_vv_pruefung_learning_path,
) )
from vbv_lernwelt.learnpath.creators import assign_circles_to_profiles
from vbv_lernwelt.learnpath.models import ( from vbv_lernwelt.learnpath.models import (
Circle, Circle,
LearningContent, LearningContent,
@ -222,6 +223,7 @@ def create_versicherungsvermittlerin_course(
create_vv_gewinnen_casework(course_id=course_id) create_vv_gewinnen_casework(course_id=course_id)
create_vv_reflection(course_id=course_id) create_vv_reflection(course_id=course_id)
create_vv_new_learning_path(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]) cs = CourseSession.objects.create(course_id=course_id, title=names[language])

View File

@ -1,3 +1,6 @@
import structlog
from vbv_lernwelt.course.consts import COURSE_VERSICHERUNGSVERMITTLERIN_ID
from vbv_lernwelt.learnpath.consts import ( from vbv_lernwelt.learnpath.consts import (
COURSE_PROFILE_KRANKENZUSATZ_CODE, COURSE_PROFILE_KRANKENZUSATZ_CODE,
COURSE_PROFILE_KRANKENZUSATZ_ID, COURSE_PROFILE_KRANKENZUSATZ_ID,
@ -7,6 +10,8 @@ from vbv_lernwelt.learnpath.consts import (
COURSE_PROFILE_NICHTLEBEN_ID, COURSE_PROFILE_NICHTLEBEN_ID,
) )
logger = structlog.get_logger(__name__)
def create_course_profiles(): def create_course_profiles():
from vbv_lernwelt.learnpath.models import CourseProfile from vbv_lernwelt.learnpath.models import CourseProfile
@ -20,3 +25,53 @@ def create_course_profiles():
CourseProfile.objects.create( CourseProfile.objects.create(
id=COURSE_PROFILE_KRANKENZUSATZ_ID, code=COURSE_PROFILE_KRANKENZUSATZ_CODE 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")

View File

@ -307,7 +307,7 @@ class CircleObjectType(DjangoObjectType):
class Meta: class Meta:
model = Circle model = Circle
interfaces = (CoursePageInterface,) interfaces = (CoursePageInterface,)
fields = ["description", "goals"] fields = ["description", "goals", "is_base_circle"]
def resolve_learning_sequences(self: Circle, info, **kwargs): def resolve_learning_sequences(self: Circle, info, **kwargs):
circle_descendants = None circle_descendants = None
@ -336,10 +336,9 @@ class CircleObjectType(DjangoObjectType):
if descendant.specific_class == LearningSequence if descendant.specific_class == LearningSequence
] ]
def resolve_profiles(self, info, **kwargs): @staticmethod
# choices = ["life", "nonlife", "sick"] def resolve_profiles(root: Circle, info, **kwargs):
choices = CourseProfile.objects.all() return root.profiles.all()
return [random.choice(choices).code]
class TopicObjectType(DjangoObjectType): class TopicObjectType(DjangoObjectType):