def test_order_find_related_tutors_somebody(self):
        # Create tutor - Dupont Tom
        tutor_five = TutorFactory(
            person=PersonFactory(last_name='Dupont', first_name='Tom'))
        test_attribution.create_attribution(
            tutor=tutor_five, learning_unit_year=self.learning_unit_year)
        # Create tutor - Dupont Albert
        tutor_third = TutorFactory(
            person=PersonFactory(last_name='Dupont', first_name='Albert'))
        test_attribution.create_attribution(
            tutor=tutor_third, learning_unit_year=self.learning_unit_year)
        # Create tutor - Armand Zoe
        tutor_second = TutorFactory(
            person=PersonFactory(last_name='Armand', first_name='Zoe'))
        test_attribution.create_attribution(
            tutor=tutor_second, learning_unit_year=self.learning_unit_year_2)
        # Create tutor - SOMEBODY_GID [Specific case: Must be at top of list - Global_id: 99999998]
        tutor_first = TutorFactory(
            person=PersonFactory(last_name='SOMEBODY_GID',
                                 first_name='SOMEBODY_GID',
                                 global_id='99999998'))
        test_attribution.create_attribution(
            tutor=tutor_first, learning_unit_year=self.learning_unit_year_2)

        tutors = list(
            score_encoding_progress.find_related_tutors(
                self.program_manager.person.user, self.academic_year,
                number_session.ONE))
        self.assertEqual(len(tutors), 5)
        self.assertEqual(tutors[0], tutor_first)  #SOMEBODY_GID
        self.assertEqual(tutors[1], tutor_second)  #Armand Zoe
        self.assertEqual(tutors[2], tutor_third)  #Dupont Albert
        self.assertEqual(tutors[3],
                         self.tutor)  #Dupont Thierry [ Set in setUp fct ]
        self.assertEqual(tutors[4], tutor_five)  #Dupont Tom
Beispiel #2
0
    def test_find_related_tutors(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)
        test_attribution.create_attribution(tutor=TutorFactory(), learning_unit_year=self.learning_unit_year_2)
        test_attribution.create_attribution(tutor=TutorFactory(), learning_unit_year=self.learning_unit_year_2)

        tutors = list(score_encoding_progress.find_related_tutors(self.program_manager.person.user, self.academic_year,
                                                                  number_session.ONE))
        self.assertEqual(len(tutors), 5)
Beispiel #3
0
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)