From f3da6d3c9d8db1466781db3e0caac3a04473c9c4 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Fri, 3 Nov 2023 11:06:27 +0100 Subject: [PATCH] fix: filter out participants which are not anymore in the course session --- .../dashboard/graphql/types/attendance.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/vbv_lernwelt/dashboard/graphql/types/attendance.py b/server/vbv_lernwelt/dashboard/graphql/types/attendance.py index d6bb1e22..3f7488ae 100644 --- a/server/vbv_lernwelt/dashboard/graphql/types/attendance.py +++ b/server/vbv_lernwelt/dashboard/graphql/types/attendance.py @@ -52,15 +52,21 @@ def attendance_day_presences( url = f"/course/{course_session.course.slug}/cockpit/attendance?id={attendance_day.learning_content.id}&courseSessionId={course_session.id}" - participants_total = CourseSessionUser.objects.filter( - course_session=course_session, role=CourseSessionUser.Role.MEMBER - ).count() - + participant_user_ids = [ + str(user_id) + for user_id in CourseSessionUser.objects.filter( + course_session=course_session, role=CourseSessionUser.Role.MEMBER + ).values_list("user_id", flat=True) + ] + participants_total = len(participant_user_ids) participants_present = len( [ participant for participant in attendance_day.attendance_user_list if participant["status"] == AttendanceUserStatus.PRESENT.value + # in the `attendance_user_list` are users present, which are not + # (anymore) in the course session -> so we need to filter them out + and participant["user_id"] in participant_user_ids ] )