Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def apply_action_on_proposals(proposals, author, post_data, research_criteria):
    if not bool(proposals):
        return {WARNING: [_("No proposals was selected.")]}

    action = post_data.get("action", "")
    messages_by_level = {}
    if action == ACTION_BACK_TO_INITIAL:
        messages_by_level = proposal_business.cancel_proposals_and_send_report(proposals, author, research_criteria)
    elif action == ACTION_CONSOLIDATE:
        messages_by_level = proposal_business.consolidate_proposals_and_send_report(proposals, author,
                                                                                    research_criteria)
    elif action == ACTION_FORCE_STATE:
        form = ProposalStateModelForm(post_data)
        if form.is_valid():
            new_state = form.cleaned_data.get("state")
            messages_by_level = proposal_business.force_state_of_proposals(proposals, author, new_state)
    return messages_by_level
Ejemplo n.º 3
0
def edit_learning_unit_proposal(request, learning_unit_year_id):
    user_person = get_object_or_404(Person, user=request.user)

    context = get_learning_unit_identification_context(learning_unit_year_id, user_person)
    proposal = proposal_learning_unit.find_by_learning_unit_year(learning_unit_year_id)

    proposal_form = ProposalStateModelForm(request.POST or None, instance=proposal)
    if proposal_form.is_valid():
        try:
            proposal_form.save()
            display_success_messages(request, _("proposal_edited_successfully"))
            return HttpResponseRedirect(reverse('learning_unit', args=[learning_unit_year_id]))

        except (IntegrityError, ValueError) as e:
            display_error_messages(request, e.args[0])

    context['form'] = proposal_form
    return layout.render(request, 'learning_unit/proposal/edition_proposal_state.html', context)
Ejemplo n.º 4
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
Ejemplo n.º 5
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)