def get_scores_encoding_list(user, **kwargs): current_academic_year = academic_year.current_academic_year() current_number_session = session_exam_calendar.find_session_exam_number() is_program_manager = program_manager.is_program_manager(user) learning_unit_year_id = kwargs.get('learning_unit_year_id') offer_year_id = kwargs.get('offer_year_id') tutor_id = kwargs.get('tutor_id') enrollments_ids = kwargs.get('enrollments_ids') justification = kwargs.get('justification') only_enrolled = _need_to_filter_students_enrolled_to_exam( justification, kwargs) if is_program_manager: professor = tutor.find_by_id(tutor_id) if tutor_id else None offers_year = [offer_year.find_by_id(offer_year_id)] if offer_year_id else \ list(offer_year.find_by_user(user, academic_yr=current_academic_year)) enrollments = exam_enrollment.find_for_score_encodings( academic_year=current_academic_year, session_exam_number=current_number_session, learning_unit_year_id=learning_unit_year_id, tutor=professor, offers_year=offers_year, registration_id=kwargs.get('registration_id'), student_last_name=kwargs.get('student_last_name'), student_first_name=kwargs.get('student_first_name'), justification=justification, only_enrolled=only_enrolled, ) else: professor = tutor.find_by_user(user) enrollments = exam_enrollment.find_for_score_encodings( academic_year=current_academic_year, session_exam_number=current_number_session, learning_unit_year_id=learning_unit_year_id, tutor=professor, only_enrolled=only_enrolled) # Want a subset of exam enrollment list if enrollments_ids: enrollments = enrollments.filter(id__in=enrollments_ids) # Append deadline/deadline_tutor for each exam enrollments enrollments = _append_session_exam_deadline(list(enrollments)) enrollments = sort_encodings(enrollments) return ScoresEncodingList( **{ 'academic_year': current_academic_year, 'number_session': current_number_session, 'learning_unit_year': learning_unit_year.get_by_id(learning_unit_year_id ) if learning_unit_year_id else None, 'enrollments': enrollments })
def get_scores_encoding_list(user, **kwargs): current_academic_year = academic_year.current_academic_year() current_number_session = session_exam_calendar.find_session_exam_number() is_program_manager = program_manager.is_program_manager(user) learning_unit_year_id = kwargs.get('learning_unit_year_id') offer_year_id = kwargs.get('offer_year_id') tutor_id = kwargs.get('tutor_id') enrollments_ids = kwargs.get('enrollments_ids') justification = kwargs.get('justification') only_enrolled = _need_to_filter_students_enrolled_to_exam(justification, kwargs) if is_program_manager: professor = tutor.find_by_id(tutor_id) if tutor_id else None offers_year = [offer_year.find_by_id(offer_year_id)] if offer_year_id else \ list(offer_year.find_by_user(user, academic_yr=current_academic_year)) enrollments = exam_enrollment.find_for_score_encodings( academic_year=current_academic_year, session_exam_number=current_number_session, learning_unit_year_id=learning_unit_year_id, tutor=professor, offers_year=offers_year, registration_id=kwargs.get('registration_id'), student_last_name=kwargs.get('student_last_name'), student_first_name=kwargs.get('student_first_name'), justification=justification, only_enrolled=only_enrolled, ) else: professor = tutor.find_by_user(user) enrollments = exam_enrollment.find_for_score_encodings( academic_year=current_academic_year, session_exam_number=current_number_session, learning_unit_year_id=learning_unit_year_id, tutor=professor, only_enrolled=only_enrolled ) # Want a subset of exam enrollment list if enrollments_ids: enrollments = enrollments.filter(id__in=enrollments_ids) # Append deadline/deadline_tutor for each exam enrollments enrollments = _append_session_exam_deadline(list(enrollments)) enrollments = sort_encodings(enrollments) return ScoresEncodingList(**{ 'academic_year': current_academic_year, 'number_session': current_number_session, 'learning_unit_year': learning_unit_year.get_by_id(learning_unit_year_id) if learning_unit_year_id else None, 'enrollments': enrollments })
def find_related_tutors(user, academic_year, session_exam_number): # Find all offer managed by current user offer_year_ids = list(offer_year.find_by_user(user).values_list('id', flat=True)) learning_unit_year_ids = list(exam_enrollment.find_for_score_encodings(session_exam_number=session_exam_number, academic_year=academic_year, offers_year=offer_year_ids, with_session_exam_deadline=False)\ .distinct('learning_unit_enrollment__learning_unit_year')\ .values_list('learning_unit_enrollment__learning_unit_year_id', flat=True)) tutors = tutor.find_by_learning_unit(learning_unit_year_ids) return sorted(tutors, key=_order_by_last_name_and_first_name)
def find_related_tutors(user, academic_year, session_exam_number): # Find all offer managed by current user offer_year_ids = list(offer_year.find_by_user(user).values_list('id', flat=True)) learning_unit_year_ids = list(exam_enrollment.find_for_score_encodings(session_exam_number=session_exam_number, academic_year=academic_year, offers_year=offer_year_ids, with_session_exam_deadline=False)\ .distinct('learning_unit_enrollment__learning_unit_year')\ .values_list('learning_unit_enrollment__learning_unit_year_id', flat=True)) tutors = tutor.find_by_learning_unit(learning_unit_year_ids) return sorted(tutors, key=_order_by_last_name_and_first_name)
def test_find_for_score_encodings_enrolled_state_only(self): self.assertCountEqual(exam_enrollment.find_for_score_encodings( session_exam_number=1, only_enrolled=True ), [self.exam_enrollment])
def test_find_for_score_encodings_for_all_enrollement_state(self): self.assertCountEqual(exam_enrollment.find_for_score_encodings( session_exam_number=1, ), [self.exam_enrollment, self.exam_enrollment_2])