diff --git a/server/vbv_lernwelt/core/create_default_users.py b/server/vbv_lernwelt/core/create_default_users.py index f7f60a2a..eab3f30f 100644 --- a/server/vbv_lernwelt/core/create_default_users.py +++ b/server/vbv_lernwelt/core/create_default_users.py @@ -258,6 +258,11 @@ def create_default_users(default_password="test", set_avatar=False): ) _create_student_user( id=TEST_STUDENT3_VV_USER_ID, + email="student-vv3@eiger-versicherungen.ch", + first_name="Vladi", + last_name="Volodemir", + ) + _create_student_user( email="patrizia.huggel@eiger-versicherungen.ch", first_name="Patrizia", last_name="Huggel", @@ -424,7 +429,7 @@ def create_default_users(default_password="test", set_avatar=False): ) _create_user( _id=TEST_AUSBILDUNGSVERANTWORTLICHER1_USER_ID, - email="test-lernbegleiter1@example.com", + email="test-ausbildungsverantwortlicher1@example.com", first_name="Bruno", last_name="Banani-Ausbildungsverantwortlicher", password=default_password, diff --git a/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py b/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py index bdca5301..645773df 100644 --- a/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py +++ b/server/vbv_lernwelt/dashboard/graphql/types/dashboard.py @@ -1,6 +1,8 @@ +from collections import defaultdict from itertools import groupby import graphene +from django.db.models.functions import ExtractYear from graphene import Enum from vbv_lernwelt.course.graphql.types import ( @@ -306,21 +308,26 @@ class TrainingResponsibleStatisticsType(graphene.ObjectType): @staticmethod def resolve_participants_per_year(root, info): user = info.context.user - course_session_users = CourseSessionUser.objects.filter( - agentparticipantrelation__agent=user, - agentparticipantrelation__participant__course_session=root.course_session_id, + course_session_users = ( + CourseSessionUser.objects.filter( + agentparticipantrelation__agent=user, + agentparticipantrelation__participant__course_session=root.course_session_id, + ) + .annotate( + checkout_year=ExtractYear("user__checkout_information__created_at") + ) + .select_related("user") ) - - grouped_course_session_users = groupby( - sorted(course_session_users, key=lambda x: x.created_at.year), - key=lambda x: x.created_at.year, - ) - + grouped_course_session_users = defaultdict(list) + for csu in course_session_users: + checkout_year = csu.checkout_year + if checkout_year: + grouped_course_session_users[checkout_year].append(csu) return [ ParticipantsForYear( _id=f"{root.course_session_id} {year}", year=year, - participants=list(c), + participants=participants, ) - for year, c in grouped_course_session_users + for year, participants in grouped_course_session_users.items() ]