diff --git a/server/vbv_lernwelt/course/creators/test_utils.py b/server/vbv_lernwelt/course/creators/test_utils.py index 51360fc6..1a76a3ca 100644 --- a/server/vbv_lernwelt/course/creators/test_utils.py +++ b/server/vbv_lernwelt/course/creators/test_utils.py @@ -46,6 +46,7 @@ from vbv_lernwelt.learnpath.models import ( LearningContentAssignment, LearningContentEdoniqTest, LearningPath, + LearningUnit, ) from vbv_lernwelt.learnpath.tests.learning_path_factories import ( CircleFactory, @@ -268,13 +269,18 @@ def create_course_session_edoniq_test( return cset -def create_learning_unit(circle: Circle, course: Course): +def create_learning_unit( + circle: Circle, + course: Course, +) -> LearningUnit: cat, _ = CourseCategory.objects.get_or_create( course=course, title="Course Category" ) return LearningUnitFactory( - title="Learning Unit", parent=circle, course_category=cat + title="Learning Unit", + parent=circle, + course_category=cat, ) diff --git a/server/vbv_lernwelt/learning_mentor/content/self_evaluation_feedback.py b/server/vbv_lernwelt/learning_mentor/content/self_evaluation_feedback.py index 36785f22..bcee4075 100644 --- a/server/vbv_lernwelt/learning_mentor/content/self_evaluation_feedback.py +++ b/server/vbv_lernwelt/learning_mentor/content/self_evaluation_feedback.py @@ -1,14 +1,17 @@ from typing import List, Set, Tuple -from django.db.models import Prefetch - from vbv_lernwelt.core.models import User +from vbv_lernwelt.course.models import Course from vbv_lernwelt.learning_mentor.entities import ( MentorAssignmentCompletion, MentorAssignmentStatus, MentorAssignmentStatusType, MentorCompletionStatus, ) +from vbv_lernwelt.learnpath.models import ( + LearningUnit, + LearningUnitPerformanceFeedbackType, +) from vbv_lernwelt.self_evaluation_feedback.models import SelfEvaluationFeedback @@ -37,7 +40,9 @@ def create_blank_completions_non_requesters( def get_self_feedback_evaluation( - participants: List[User], evaluation_user: User + participants: List[User], + evaluation_user: User, + course: Course, ) -> Tuple[List[MentorAssignmentStatus], Set[int]]: records: List[MentorAssignmentStatus] = [] circle_ids: Set[int] = set() @@ -45,21 +50,24 @@ def get_self_feedback_evaluation( if not participants: return records, circle_ids - feedbacks = SelfEvaluationFeedback.objects.prefetch_related( - Prefetch("learning_unit") - ).filter( - feedback_requester_user__in=participants, - feedback_provider_user=evaluation_user, - ) + # very unfortunate: we can't simply get all SelfEvaluationFeedback objects since then + # we would miss the one where no feedback was requested -> so we get all learning units + # and check if we have to take them into account (course, feedback type, etc.) + for learning_unit in LearningUnit.objects.filter( + feedback_user=LearningUnitPerformanceFeedbackType.MENTOR_FEEDBACK.value, + ): + circle_page = learning_unit.get_parent() + circle = circle_page.specific - feedback_by_learning_unit = {} + if circle.get_course() != course: + continue - for feedback in feedbacks: - feedback_by_learning_unit.setdefault(feedback.learning_unit, []).append( - feedback + feedbacks = SelfEvaluationFeedback.objects.filter( + learning_unit=learning_unit, + feedback_requester_user__in=participants, + feedback_provider_user=evaluation_user, ) - for learning_unit, feedbacks in feedback_by_learning_unit.items(): circle_id = learning_unit.get_circle().id circle_ids.add(circle_id) diff --git a/server/vbv_lernwelt/learning_mentor/tests/test_mentor.py b/server/vbv_lernwelt/learning_mentor/tests/test_mentor.py index 91e2b8d9..fb27b620 100644 --- a/server/vbv_lernwelt/learning_mentor/tests/test_mentor.py +++ b/server/vbv_lernwelt/learning_mentor/tests/test_mentor.py @@ -23,6 +23,7 @@ from vbv_lernwelt.course.creators.test_utils import ( ) from vbv_lernwelt.course.models import CourseSessionUser from vbv_lernwelt.learning_mentor.models import LearningMentor +from vbv_lernwelt.learnpath.models import LearningUnitPerformanceFeedbackType from vbv_lernwelt.self_evaluation_feedback.models import SelfEvaluationFeedback @@ -131,6 +132,13 @@ class LearningMentorAPITest(APITestCase): course=self.course, ) + # performance criteria under this learning unit shall be evaluated by the mentor + learning_unit.feedback_user = ( + LearningUnitPerformanceFeedbackType.MENTOR_FEEDBACK.name + ) + + learning_unit.save() + # 1: we already evaluated SelfEvaluationFeedback.objects.create( feedback_requester_user=self.participant_1.user, diff --git a/server/vbv_lernwelt/learning_mentor/views.py b/server/vbv_lernwelt/learning_mentor/views.py index a1966c8f..e56c33fc 100644 --- a/server/vbv_lernwelt/learning_mentor/views.py +++ b/server/vbv_lernwelt/learning_mentor/views.py @@ -52,6 +52,7 @@ def mentor_summary(request, course_session_id: int): ) = get_self_feedback_evaluation( participants=users, evaluation_user=request.user, # noqa + course=course_session.course, ) circle_ids.update(praxis_assignments_circle_ids)