Exemple #1
0
    def test_internship_subtype(self):
        self.form_data[
            "internship_subtype"] = internship_subtypes.TEACHING_INTERNSHIP
        form = LearningUnitProposalModificationForm(self.form_data,
                                                    self.person)

        self.assertFalse(form.is_valid())
        self.assertIn(_("learning_unit_type_is_not_internship"),
                      form.errors["internship_subtype"])
Exemple #2
0
def _update_proposal(request, user_person, proposal):
    initial_data = compute_form_initial_data(proposal.learning_unit_year)
    initial_data.update(_build_proposal_data(proposal))

    # Workaround Set initial data from proposal initial data json to compute effectively data modified
    # and compute proposal type
    initial_data_from_json = compute_form_initial_data_from_proposal_json(
        proposal.initial_data)
    initial_data_from_json.update(_build_proposal_data(proposal))

    proposal_form = LearningUnitProposalModificationForm(
        request.POST or None,
        initial=initial_data_from_json,
        instance=proposal,
        learning_unit=proposal.learning_unit_year.learning_unit,
        person=user_person)

    if proposal_form.is_valid():
        try:
            changed_fields = proposal_form.changed_data_for_fields_that_can_be_modified
            type_proposal = business_proposal.compute_proposal_type(
                changed_fields, initial_data_from_json.get("type"))
            proposal_form.save(proposal.learning_unit_year, type_proposal,
                               proposal_form.cleaned_data.get("state"))
            display_success_messages(request,
                                     _("proposal_edited_successfully"))
            return HttpResponseRedirect(
                reverse('learning_unit',
                        args=[proposal.learning_unit_year.id]))
        except (IntegrityError, ValueError) as e:
            display_error_messages(request, e.args[0])

    proposal_form.initial = initial_data

    return layout.render(
        request, 'learning_unit/proposal/update_modification.html', {
            'learning_unit_year': proposal.learning_unit_year,
            'person': user_person,
            'form': proposal_form,
            'experimental_phase': True
        })
def propose_modification_of_learning_unit(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(LearningUnitYear,
                                           id=learning_unit_year_id)
    user_person = get_object_or_404(Person, user=request.user)

    if not is_eligible_for_modification_proposal(learning_unit_year,
                                                 user_person):
        raise PermissionDenied(
            "Learning unit year not eligible for proposal or user has not sufficient rights."
        )

    initial_data = compute_form_initial_data(learning_unit_year)

    if request.method == 'POST':
        modified_post_data = request.POST.copy()
        modified_post_data["academic_year"] = str(
            learning_unit_year.academic_year.id)
        form = LearningUnitProposalModificationForm(modified_post_data,
                                                    initial=initial_data)
        if form.is_valid():
            type_proposal = compute_proposal_type(form.initial,
                                                  form.cleaned_data)
            form.save(learning_unit_year, user_person, type_proposal,
                      proposal_state.ProposalState.FACULTY.name)
            messages.add_message(
                request, messages.SUCCESS,
                _("success_modification_proposal").format(
                    type_proposal, learning_unit_year.acronym))
            return redirect('learning_unit',
                            learning_unit_year_id=learning_unit_year.id)
    else:
        form = LearningUnitProposalModificationForm(initial=initial_data)

    return render(
        request, 'proposal/learning_unit_modification.html', {
            'learning_unit_year': learning_unit_year,
            'person': user_person,
            'form': form,
            'experimental_phase': True
        })
def propose_modification_of_learning_unit(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(LearningUnitYear, id=learning_unit_year_id)
    user_person = get_object_or_404(Person, user=request.user)
    initial_data = compute_form_initial_data(learning_unit_year)

    if request.method == 'POST':
        form = LearningUnitProposalModificationForm(request.POST, initial=initial_data)
        if form.is_valid():
            type_proposal = compute_proposal_type(initial_data, request.POST)
            form.save(learning_unit_year, user_person, type_proposal, proposal_state.ProposalState.FACULTY.name)
            messages.add_message(request, messages.SUCCESS,
                                 _("success_modification_proposal")
                                 .format(_(type_proposal), learning_unit_year.acronym))
            return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id)
    else:
        form = LearningUnitProposalModificationForm(initial=initial_data)

    return render(request, 'learning_unit/proposal/update.html', {
        'learning_unit_year': learning_unit_year,
        'person': user_person,
        'form': form,
        'experimental_phase': True})
Exemple #5
0
def learning_unit_modification_proposal(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(LearningUnitYear,
                                           id=learning_unit_year_id)
    user_person = get_object_or_404(Person, user=request.user)
    initial_data = compute_form_initial_data(learning_unit_year)
    proposal = proposal_learning_unit.find_by_learning_unit_year(
        learning_unit_year)

    form = LearningUnitProposalModificationForm(
        request.POST or None,
        initial=initial_data,
        instance=proposal,
        learning_unit=learning_unit_year.learning_unit,
        person=user_person)

    if form.is_valid():
        type_proposal = business_proposal.compute_proposal_type(
            form.changed_data_for_fields_that_can_be_modified,
            initial_data.get("type"))
        form.save(learning_unit_year, type_proposal,
                  compute_proposal_state(user_person))

        display_success_messages(
            request,
            _("success_modification_proposal").format(
                _(type_proposal), learning_unit_year.acronym))

        return redirect('learning_unit',
                        learning_unit_year_id=learning_unit_year.id)

    return layout.render(
        request, 'learning_unit/proposal/create_modification.html', {
            'learning_unit_year': learning_unit_year,
            'person': user_person,
            'form': form,
            'experimental_phase': True
        })