Beispiel #1
0
def learning_units_external_search(request):
    search_form = ExternalLearningUnitYearForm(request.GET or None,
                                               initial={'academic_year_id': current_academic_year()})
    user_person = get_object_or_404(Person, user=request.user)
    external_learning_units = []
    try:
        if search_form.is_valid():
            external_learning_units = search_form.get_learning_units()
            check_if_display_message(request, external_learning_units)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    if request.POST:
        return redirect(reverse("learning_unit_proposal_search") + "?{}".format(request.GET.urlencode()))

    context = {
        'form': search_form,
        'academic_years': get_last_academic_years(),
        'current_academic_year': current_academic_year(),
        'experimental_phase': True,
        'search_type': EXTERNAL_SEARCH,
        'learning_units': external_learning_units,
        'is_faculty_manager': user_person.is_faculty_manager(),
        'form_comparison': SelectComparisonYears(academic_year=get_academic_year_of_reference(external_learning_units)),
    }
    return layout.render(request, "learning_units.html", context)
Beispiel #2
0
def learning_units_external_search(request):
    search_form = ExternalLearningUnitYearForm(request.GET or None,
                                               initial={
                                                   'academic_year_id':
                                                   current_academic_year(),
                                                   'with_entity_subordinated':
                                                   True
                                               })
    user_person = get_object_or_404(Person, user=request.user)
    found_learning_units = LearningUnitYear.objects.none()

    if search_form.is_valid():
        found_learning_units = search_form.get_queryset()
        check_if_display_message(request, found_learning_units)

    context = {
        'form':
        search_form,
        'academic_years':
        get_last_academic_years(),
        'current_academic_year':
        current_academic_year(),
        'search_type':
        EXTERNAL_SEARCH,
        'learning_units_count':
        found_learning_units.count(),
        'is_faculty_manager':
        user_person.is_faculty_manager,
        'form_comparison':
        SelectComparisonYears(academic_year=get_academic_year_of_reference(
            found_learning_units)),
        'page_obj':
        paginate_queryset(found_learning_units, request.GET),
    }
    return render(request, "learning_units.html", context)
Beispiel #3
0
def learning_units_proposal_search(request):
    search_form = LearningUnitProposalForm(request.GET or None, initial={'academic_year_id': current_academic_year()})
    user_person = get_object_or_404(Person, user=request.user)
    proposals = []
    research_criteria = []
    try:
        if search_form.is_valid():
            research_criteria = get_research_criteria(search_form)
            proposals = search_form.get_proposal_learning_units()
            check_if_display_message(request, proposals)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    if request.GET.get('xls_status') == "xls":
        return create_xls_proposal(request.user, proposals, _get_filter(search_form, PROPOSAL_SEARCH))

    if request.POST:
        selected_proposals_id = request.POST.getlist("selected_action", default=[])
        selected_proposals = ProposalLearningUnit.objects.filter(id__in=selected_proposals_id)
        messages_by_level = apply_action_on_proposals(selected_proposals, user_person, request.POST, research_criteria)
        display_messages_by_level(request, messages_by_level)
        return redirect(reverse("learning_unit_proposal_search") + "?{}".format(request.GET.urlencode()))

    context = {
        'form': search_form,
        'form_proposal_state': ProposalStateModelForm(),
        'academic_years': get_last_academic_years(),
        'current_academic_year': current_academic_year(),
        'experimental_phase': True,
        'search_type': PROPOSAL_SEARCH,
        'proposals': proposals,
        'is_faculty_manager': user_person.is_faculty_manager(),
        'form_comparison': SelectComparisonYears(academic_year=get_academic_year_of_reference(proposals)),
    }
    return layout.render(request, "learning_units.html", context)
Beispiel #4
0
def learning_units_search(request, search_type):
    service_course_search = search_type == SERVICE_COURSES_SEARCH
    borrowed_course_search = search_type == BORROWED_COURSE

    form = LearningUnitYearForm(
        request.GET or None,
        service_course_search=service_course_search,
        borrowed_course_search=borrowed_course_search,
        initial={'academic_year_id': starting_academic_year()}
    )
    found_learning_units = LearningUnitYear.objects.none()
    try:
        if form.is_valid():
            found_learning_units = form.get_activity_learning_units()
            check_if_display_message(request, found_learning_units)

    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    if request.POST.get('xls_status') == "xls":
        return create_xls(request.user, found_learning_units, _get_filter(form, search_type))

    if request.POST.get('xls_status') == "xls_comparison":
        return create_xls_comparison(
            request.user,
            found_learning_units,
            _get_filter(form, search_type),
            request.POST.get('comparison_year')
        )

    if request.POST.get('xls_status') == "xls_with_parameters":
        return create_xls_with_parameters(
            request.user,
            found_learning_units,
            _get_filter(form, search_type),
            {
                WITH_GRP: request.POST.get('with_grp') == 'true',
                WITH_ATTRIBUTIONS: request.POST.get('with_attributions') == 'true'
            }
        )

    form_comparison = SelectComparisonYears(academic_year=get_academic_year_of_reference(found_learning_units))

    context = {
        'form': form,
        'academic_years': get_last_academic_years(),
        'container_types': learning_container_year_types.LEARNING_CONTAINER_YEAR_TYPES,
        'types': learning_unit_year_subtypes.LEARNING_UNIT_YEAR_SUBTYPES,
        'learning_units_count': len(found_learning_units)
        if isinstance(found_learning_units, list) else
        found_learning_units.count(),
        'current_academic_year': starting_academic_year(),
        'experimental_phase': True,
        'search_type': search_type,
        'is_faculty_manager': request.user.person.is_faculty_manager,
        'form_comparison': form_comparison,
        'page_obj': paginate_queryset(found_learning_units, request.GET),
    }

    return render(request, "learning_units.html", context)
Beispiel #5
0
def learning_units_summary_list(request):
    a_user_person = request.user.person
    found_learning_units = LearningUnitYear.objects.none()

    initial_academic_year = current_academic_year()
    if academic_calendar.is_academic_calendar_has_started(
            initial_academic_year, SUMMARY_COURSE_SUBMISSION):
        initial_academic_year = initial_academic_year.next()

    search_form = LearningUnitYearForm(request.GET or None,
                                       initial={
                                           'academic_year_id':
                                           initial_academic_year,
                                           'with_entity_subordinated': True
                                       })
    try:
        if search_form.is_valid():
            found_learning_units = search_form.get_learning_units_and_summary_status(
                requirement_entities=a_user_person.find_main_entities_version,
            )
            check_if_display_message(request, found_learning_units)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')

    responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list(
        found_learning_units)

    for luy in found_learning_units:
        luy.errors = can_learning_unit_year_educational_information_be_udpated(
            learning_unit_year_id=luy)

    if request.GET.get('xls_status') == "xls_teaching_material":
        try:
            return generate_xls_teaching_material(request.user,
                                                  found_learning_units)
        except ObjectDoesNotExist:
            display_warning_messages(
                request,
                _("the list to generate is empty.").capitalize())

    form_comparison = SelectComparisonYears(
        academic_year=get_academic_year_of_reference(found_learning_units))

    context = {
        'form': search_form,
        'formset': _get_formset(request,
                                responsible_and_learning_unit_yr_list),
        'learning_units_count': found_learning_units.count(),
        'search_type': SUMMARY_LIST,
        'is_faculty_manager': a_user_person.is_faculty_manager,
        'form_comparison': form_comparison,
        'page_obj': paginate_queryset(found_learning_units, request.GET),
    }

    return render(request, "learning_units.html", context)
Beispiel #6
0
def learning_units_summary_list(request):
    a_user_person = find_by_user(request.user)
    learning_units_found = []

    initial_academic_year = current_academic_year()
    if academic_calendar.is_academic_calendar_has_started(
            initial_academic_year, SUMMARY_COURSE_SUBMISSION):
        initial_academic_year = initial_academic_year.next()

    search_form = LearningUnitYearForm(
        request.GET or None,
        initial={'academic_year_id': initial_academic_year})
    try:
        if search_form.is_valid():
            learning_units_found_search = search_form.get_learning_units(
                requirement_entities=a_user_person.find_main_entities_version,
                luy_status=True)

            # TODO refactoring : too many queries
            learning_units_found = get_learning_units_and_summary_status(
                learning_units_found_search)
            check_if_display_message(request, learning_units_found_search)
    except TooManyResultsException:
        display_error_messages(request, 'too_many_results')
    responsible_and_learning_unit_yr_list = get_responsible_and_learning_unit_yr_list(
        learning_units_found)
    learning_units = sorted(learning_units_found,
                            key=lambda learning_yr: learning_yr.acronym)
    errors = [
        can_learning_unit_year_educational_information_be_udpated(
            learning_unit_year_id=luy.id) for luy in learning_units
    ]

    if request.GET.get('xls_status') == "xls_teaching_material":
        try:
            return generate_xls_teaching_material(request.user,
                                                  learning_units_found)
        except ObjectDoesNotExist:
            display_warning_messages(
                request,
                _("the list to generate is empty.").capitalize())

    form_comparison = SelectComparisonYears(
        academic_year=get_academic_year_of_reference(learning_units_found))
    context = {
        'form': search_form,
        'formset': _get_formset(request,
                                responsible_and_learning_unit_yr_list),
        'learning_units_with_errors': list(zip(learning_units, errors)),
        'search_type': SUMMARY_LIST,
        'is_faculty_manager': a_user_person.is_faculty_manager(),
        'form_comparison': form_comparison
    }

    return layout.render(request, "learning_units.html", context)
Beispiel #7
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        form = context["form"]
        select_comparison_form_academic_year = context["proposal_academic_year"]
        if form.is_valid():
            select_comparison_form_academic_year = form.cleaned_data["academic_year"] or \
                                                   select_comparison_form_academic_year

        context.update({
            "form_comparison": SelectComparisonYears(academic_year=select_comparison_form_academic_year),
        })
        return context
Beispiel #8
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        form = context["form"]
        select_comparison_form_academic_year = context["proposal_academic_year"]
        if form.is_valid():
            select_comparison_form_academic_year = form.cleaned_data["academic_year"] or \
                                                   select_comparison_form_academic_year
        user_person = get_object_or_404(Person, user=self.request.user)
        context.update({
            'form_proposal_state': ProposalStateModelForm(is_faculty_manager=user_person.is_faculty_manager),
            'can_change_proposal_state': user_person.is_faculty_manager or user_person.is_central_manager,
            "form_comparison": SelectComparisonYears(academic_year=select_comparison_form_academic_year),
        })
        return context
Beispiel #9
0
def learning_units_proposal_search(request):
    search_form = LearningUnitProposalForm(
        request.GET or None,
        initial={'academic_year_id': current_academic_year()}
    )
    user_person = get_object_or_404(Person, user=request.user)
    found_learning_units = LearningUnitYear.objects.none()

    if search_form.is_valid():
        found_learning_units = search_form.get_proposal_learning_units()
        check_if_display_message(request, found_learning_units)

    if request.POST.get('xls_status_proposal') == "xls":
        return create_xls_proposal(
            user_person.user,
            list(found_learning_units),
            _get_filter(search_form, PROPOSAL_SEARCH)
        )

    if request.POST:
        research_criteria = get_research_criteria(search_form) if search_form.is_valid() else []

        selected_proposals_id = request.POST.getlist("selected_action", default=[])
        selected_proposals = ProposalLearningUnit.objects.filter(id__in=selected_proposals_id)
        messages_by_level = apply_action_on_proposals(selected_proposals, user_person, request.POST, research_criteria)
        display_messages_by_level(request, messages_by_level)
        return redirect(reverse("learning_unit_proposal_search") + "?{}".format(request.GET.urlencode()))

    context = {
        'form': search_form,
        'form_proposal_state': ProposalStateModelForm(),
        'academic_years': get_last_academic_years(),
        'current_academic_year': current_academic_year(),
        'experimental_phase': True,
        'search_type': PROPOSAL_SEARCH,
        'learning_units_count': found_learning_units.count(),
        'is_faculty_manager': user_person.is_faculty_manager,
        'form_comparison': SelectComparisonYears(academic_year=get_academic_year_of_reference(found_learning_units)),
        'page_obj': paginate_queryset(found_learning_units, request.GET),
    }
    return render(request, "learning_units.html", context)