Group users by checkout information created date
This commit is contained in:
parent
294c33ddc8
commit
a29171f32f
|
|
@ -258,6 +258,11 @@ def create_default_users(default_password="test", set_avatar=False):
|
||||||
)
|
)
|
||||||
_create_student_user(
|
_create_student_user(
|
||||||
id=TEST_STUDENT3_VV_USER_ID,
|
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",
|
email="patrizia.huggel@eiger-versicherungen.ch",
|
||||||
first_name="Patrizia",
|
first_name="Patrizia",
|
||||||
last_name="Huggel",
|
last_name="Huggel",
|
||||||
|
|
@ -424,7 +429,7 @@ def create_default_users(default_password="test", set_avatar=False):
|
||||||
)
|
)
|
||||||
_create_user(
|
_create_user(
|
||||||
_id=TEST_AUSBILDUNGSVERANTWORTLICHER1_USER_ID,
|
_id=TEST_AUSBILDUNGSVERANTWORTLICHER1_USER_ID,
|
||||||
email="test-lernbegleiter1@example.com",
|
email="test-ausbildungsverantwortlicher1@example.com",
|
||||||
first_name="Bruno",
|
first_name="Bruno",
|
||||||
last_name="Banani-Ausbildungsverantwortlicher",
|
last_name="Banani-Ausbildungsverantwortlicher",
|
||||||
password=default_password,
|
password=default_password,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
from collections import defaultdict
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
from django.db.models.functions import ExtractYear
|
||||||
from graphene import Enum
|
from graphene import Enum
|
||||||
|
|
||||||
from vbv_lernwelt.course.graphql.types import (
|
from vbv_lernwelt.course.graphql.types import (
|
||||||
|
|
@ -306,21 +308,26 @@ class TrainingResponsibleStatisticsType(graphene.ObjectType):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_participants_per_year(root, info):
|
def resolve_participants_per_year(root, info):
|
||||||
user = info.context.user
|
user = info.context.user
|
||||||
course_session_users = CourseSessionUser.objects.filter(
|
course_session_users = (
|
||||||
|
CourseSessionUser.objects.filter(
|
||||||
agentparticipantrelation__agent=user,
|
agentparticipantrelation__agent=user,
|
||||||
agentparticipantrelation__participant__course_session=root.course_session_id,
|
agentparticipantrelation__participant__course_session=root.course_session_id,
|
||||||
)
|
)
|
||||||
|
.annotate(
|
||||||
grouped_course_session_users = groupby(
|
checkout_year=ExtractYear("user__checkout_information__created_at")
|
||||||
sorted(course_session_users, key=lambda x: x.created_at.year),
|
|
||||||
key=lambda x: x.created_at.year,
|
|
||||||
)
|
)
|
||||||
|
.select_related("user")
|
||||||
|
)
|
||||||
|
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 [
|
return [
|
||||||
ParticipantsForYear(
|
ParticipantsForYear(
|
||||||
_id=f"{root.course_session_id} {year}",
|
_id=f"{root.course_session_id} {year}",
|
||||||
year=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()
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue