Пример #1
0
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
        })
Пример #2
0
def get_progress_by_learning_unit_years_and_offer_years(
        user,
        session_exam_number,
        learning_unit_year_id=None,
        learning_unit_year_ids=None,
        offer_year_id=None,
        academic_year=None,
        only_enrolled=False):
    if offer_year_id:
        offer_year_ids = [offer_year_id]
    else:
        offer_year_ids = offer_year.find_by_user(user).values_list('id',
                                                                   flat=True)

    tutor_user = None
    if not program_manager.is_program_manager(user):
        tutor_user = tutor.find_by_user(user)

    queryset = find_for_score_encodings(
        session_exam_number=session_exam_number,
        learning_unit_year_id=learning_unit_year_id,
        learning_unit_year_ids=learning_unit_year_ids,
        offers_year=offer_year_ids,
        tutor=tutor_user,
        academic_year=academic_year,
        with_session_exam_deadline=False,
        only_enrolled=only_enrolled)

    return queryset.values('session_exam', 'learning_unit_enrollment__learning_unit_year',
                           'learning_unit_enrollment__offer_enrollment__offer_year') \
        .annotate(
        total_exam_enrollments=Count('id'),
        learning_unit_enrollment__learning_unit_year__acronym=
        F('learning_unit_enrollment__learning_unit_year__acronym'),
        learning_unit_enrollment__learning_unit_year__specific_title=
        F('learning_unit_enrollment__learning_unit_year__specific_title'),
        learning_unit_enrollment__learning_unit_year__learning_container_year__common_title=
        F('learning_unit_enrollment__learning_unit_year__learning_container_year__common_title'),
        exam_enrollments_encoded=Sum(Case(
            When(Q(score_final__isnull=False) | Q(justification_final__isnull=False), then=1),
            default=0,
            output_field=IntegerField())
        ),
        scores_not_yet_submitted=Sum(Case(
            When((Q(score_draft__isnull=False) &
                  Q(score_final__isnull=True) &
                  Q(justification_final__isnull=True)) | (Q(justification_draft__isnull=False) &
                                                          Q(score_final__isnull=True) &
                                                          Q(justification_final__isnull=True))
                 , then=1),
            default=0,
            output_field=IntegerField()))
    )
Пример #3
0
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
    })
Пример #4
0
def get_progress_by_learning_unit_years_and_offer_years(user,
                                                        session_exam_number,
                                                        learning_unit_year_id=None,
                                                        learning_unit_year_ids=None,
                                                        offer_year_id=None,
                                                        academic_year=None,
                                                        only_enrolled=False):
    if offer_year_id:
        offer_year_ids = [offer_year_id]
    else:
        offer_year_ids = offer_year.find_by_user(user).values_list('id', flat=True)

    tutor_user = None
    if not program_manager.is_program_manager(user):
        tutor_user = tutor.find_by_user(user)

    queryset = find_for_score_encodings(session_exam_number=session_exam_number,
                                        learning_unit_year_id=learning_unit_year_id,
                                        learning_unit_year_ids=learning_unit_year_ids,
                                        offers_year=offer_year_ids,
                                        tutor=tutor_user,
                                        academic_year=academic_year,
                                        with_session_exam_deadline=False,
                                        only_enrolled=only_enrolled)

    return queryset.values('session_exam', 'learning_unit_enrollment__learning_unit_year',
                           'learning_unit_enrollment__offer_enrollment__offer_year') \
        .annotate(
        total_exam_enrollments=Count('id'),
        learning_unit_enrollment__learning_unit_year__acronym=
        F('learning_unit_enrollment__learning_unit_year__acronym'),
        learning_unit_enrollment__learning_unit_year__specific_title=
        F('learning_unit_enrollment__learning_unit_year__specific_title'),
        learning_unit_enrollment__learning_unit_year__learning_container_year__common_title=
        F('learning_unit_enrollment__learning_unit_year__learning_container_year__common_title'),
        exam_enrollments_encoded=Sum(Case(
            When(Q(score_final__isnull=False) | Q(justification_final__isnull=False), then=1),
            default=0,
            output_field=IntegerField())
        ),
        scores_not_yet_submitted=Sum(Case(
            When((Q(score_draft__isnull=False) &
                  Q(score_final__isnull=True) &
                  Q(justification_final__isnull=True)) | (Q(justification_draft__isnull=False) &
                                                          Q(score_final__isnull=True) &
                                                          Q(justification_final__isnull=True))
                 , then=1),
            default=0,
            output_field=IntegerField()))
    )
Пример #5
0
 def test_find_by_user_wrong_id(self):
     self.assertIsNone(tutor.find_by_user(-1))
Пример #6
0
 def test_find_by_user(self):
     self.assertEqual(self.tutor, tutor.find_by_user(self.user))