def test_get_scores_encoding_progress_program_manager_with_filter_offer_year(self): progress_list = score_encoding_progress.get_scores_encoding_progress( user=self.program_manager.person.user, offer_year_id=self.offer_year_2, number_session=number_session.ONE, academic_year=self.academic_year ) self.assertEqual(len(progress_list), 1) self.assertEqual(progress_list[0].learning_unit_year_acronym, self.learning_unit_year.acronym) self.assertEqual(progress_list[0].total_exam_enrollments, 8)
def test_get_scores_encoding_progress_filter_only_incomplete(self): progress_list = score_encoding_progress.get_scores_encoding_progress( user=self.program_manager.person.user, offer_year_id=None, number_session=number_session.ONE, academic_year=self.academic_year ) progress_list = score_encoding_progress.group_by_learning_unit_year(progress_list) self.assertEqual(len(progress_list), 2) progress_list = score_encoding_progress.filter_only_incomplete(progress_list) self.assertEqual(len(progress_list), 1)
def test_get_scores_encoding_progress_tutor(self): progress_list = score_encoding_progress.get_scores_encoding_progress( user=self.tutor.person.user, offer_year_id=None, number_session=number_session.ONE, academic_year=self.academic_year) # Group by learning unit year progress_list = score_encoding_progress.group_by_learning_unit_year( progress_list) self.assertEqual(len(progress_list), 1) # CHIM1BA - LBIR1210 (10) + DIR1BA - LBIR1210(8) self.assertEqual(progress_list[0].total_exam_enrollments, 18)
def test_find_related_offer_years(self): progress_list = score_encoding_progress.get_scores_encoding_progress( user=self.program_manager.person.user, offer_year_id=None, number_session=number_session.ONE, academic_year=self.academic_year) offer_years = list( score_encoding_progress.find_related_offer_years(progress_list)) self.assertEqual(len(offer_years), 2) # Check sort by acronym self.assertEqual(offer_years[0].acronym, self.offer_year.acronym) self.assertEqual(offer_years[1].acronym, self.offer_year_2.acronym)
def test_get_scores_encoding_progress_filter_without_attribution(self): progress_list = score_encoding_progress.get_scores_encoding_progress( user=self.program_manager.person.user, offer_year_id=None, number_session=number_session.ONE, academic_year=self.academic_year ) progress_list = score_encoding_progress.group_by_learning_unit_year(progress_list) progress_list = score_encoding_progress.append_related_tutors_and_score_responsibles(progress_list) self.assertEqual(len(progress_list), 2) progress_list = score_encoding_progress.filter_only_without_attribution(progress_list) self.assertEqual(len(progress_list), 1) # LBIR1211 have no score responsible
def test_get_scores_encoding_progress_with_tutors_and_score_responsible(self): # Create tutors test_attribution.create_attribution(tutor=TutorFactory(), learning_unit_year=self.learning_unit_year) test_attribution.create_attribution(tutor=TutorFactory(), learning_unit_year=self.learning_unit_year) progress_list = score_encoding_progress.get_scores_encoding_progress( user=self.program_manager.person.user, offer_year_id=self.offer_year_2, number_session=number_session.ONE, academic_year=self.academic_year ) progress_list = score_encoding_progress.append_related_tutors_and_score_responsibles(progress_list) self.assertEqual(len(progress_list), 1) self.assertEqual(len(progress_list[0].tutors), 3) self.assertEqual(len(progress_list[0].score_responsibles), 1)
def test_get_scores_encoding_progress_program_manager(self): progress_list = score_encoding_progress.get_scores_encoding_progress( user=self.program_manager.person.user, offer_year_id=None, number_session=number_session.ONE, academic_year=self.academic_year ) # Group by learning unit year progress_list = score_encoding_progress.group_by_learning_unit_year(progress_list) self.assertEqual(len(progress_list), 2) # Check if sort by learning unit acronym self.assertEqual(progress_list[0].learning_unit_year_acronym, self.learning_unit_year.acronym) self.assertEqual(progress_list[1].learning_unit_year_acronym, self.learning_unit_year_2.acronym) # Check total enrollment self.assertEqual(progress_list[0].total_exam_enrollments, 18) self.assertEqual(progress_list[1].total_exam_enrollments, 5) # Check progress self.assertEqual(progress_list[1].progress_int, 100)
def scores_encoding(request): template_name = "scores_encoding.html" academic_yr = mdl.academic_year.current_academic_year() number_session = mdl.session_exam_calendar.find_session_exam_number() score_encoding_progress_list = None context = { 'academic_year': academic_yr, 'number_session': number_session, 'active_tab': request.GET.get('active_tab') } offer_year_id = request.GET.get('offer', None) if offer_year_id: offer_year_id = int(offer_year_id) if mdl.program_manager.is_program_manager(request.user): template_name = "scores_encoding_by_learning_unit.html" NOBODY = -1 tutor_id = request.GET.get('tutor') if tutor_id: tutor_id = int(tutor_id) learning_unit_year_acronym = request.GET.get( 'learning_unit_year_acronym') incomplete_encodings_only = request.GET.get( 'incomplete_encodings_only', False) # Manage filter learning_unit_year_ids = None if learning_unit_year_acronym: learning_unit_year_acronym = learning_unit_year_acronym.strip() \ if isinstance(learning_unit_year_acronym, str) \ else learning_unit_year_acronym learning_unit_year_ids = list(mdl.learning_unit_year.search(academic_year_id=academic_yr.id, acronym=learning_unit_year_acronym) \ .values_list('id', flat=True)) if tutor_id and tutor_id != NOBODY: learning_unit_year_ids_filter_by_tutor = mdl_attr.attribution.search( tutor=tutor_id, list_learning_unit_year=learning_unit_year_ids).distinct( 'learning_unit_year').values_list('learning_unit_year_id', flat=True) learning_unit_year_ids = list( learning_unit_year_ids_filter_by_tutor) score_encoding_progress_list = score_encoding_progress.get_scores_encoding_progress( user=request.user, offer_year_id=offer_year_id, number_session=number_session, academic_year=academic_yr, learning_unit_year_ids=learning_unit_year_ids) score_encoding_progress_list = score_encoding_progress. \ append_related_tutors_and_score_responsibles(score_encoding_progress_list) if incomplete_encodings_only: score_encoding_progress_list = score_encoding_progress.filter_only_incomplete( score_encoding_progress_list) if tutor_id == NOBODY: score_encoding_progress_list = score_encoding_progress. \ filter_only_without_attribution(score_encoding_progress_list) all_tutors = score_encoding_progress.find_related_tutors( request.user, academic_yr, number_session) all_offers = mdl.offer_year.find_by_user(request.user, academic_yr=academic_yr) if not score_encoding_progress_list: messages.add_message(request, messages.WARNING, _('No result!')) context.update({ 'offer_list': all_offers, 'tutor_list': all_tutors, 'offer_year_id': offer_year_id, 'tutor_id': tutor_id, 'learning_unit_year_acronym': learning_unit_year_acronym, 'incomplete_encodings_only': incomplete_encodings_only, 'last_synchronization': mdl.synchronization.find_last_synchronization_date() }) elif mdl.tutor.is_tutor(request.user): tutor = mdl.tutor.find_by_user(request.user) score_encoding_progress_list = score_encoding_progress.get_scores_encoding_progress( user=request.user, offer_year_id=None, number_session=number_session, academic_year=academic_yr) all_offers = score_encoding_progress.find_related_offer_years( score_encoding_progress_list) context.update({ 'tutor': tutor, 'offer_year_list': all_offers, 'offer_year_id': offer_year_id }) if score_encoding_progress_list: filtered_list = [ score_encoding for score_encoding in score_encoding_progress_list if score_encoding.offer_year_id == offer_year_id ] else: filtered_list = [] context.update({ 'notes_list': score_encoding_progress.group_by_learning_unit_year( score_encoding_progress_list) if not offer_year_id else filtered_list }) return render(request, template_name, context)