Example #1
0
def learning_unit_edition_end_date(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(LearningUnitYear,
                                           pk=learning_unit_year_id)
    person = get_object_or_404(Person, user=request.user)

    context = get_learning_unit_identification_context(learning_unit_year_id,
                                                       person)

    learning_unit_to_edit = learning_unit_year.learning_unit
    form = LearningUnitEndDateForm(request.POST or None,
                                   learning_unit=learning_unit_to_edit)
    if form.is_valid():
        try:
            result = form.save()
            display_success_messages(request, result, extra_tags='safe')

            learning_unit_year_id = _get_current_learning_unit_year_id(
                learning_unit_to_edit, learning_unit_year_id)

            return HttpResponseRedirect(
                reverse('learning_unit', args=[learning_unit_year_id]))

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

    context['form'] = form
    return layout.render(request, 'learning_unit/update_end_date.html',
                         context)
Example #2
0
def learning_unit_edition(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(LearningUnitYear,
                                           pk=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)

    learning_unit_to_edit = learning_unit_year.learning_unit
    form = LearningUnitEndDateForm(request.POST or None,
                                   learning_unit=learning_unit_to_edit)
    if form.is_valid():
        new_academic_year = form.cleaned_data['academic_year']
        try:
            result = edit_learning_unit_end_date(learning_unit_to_edit,
                                                 new_academic_year)
            display_success_messages(request, result)

            learning_unit_year_id = _get_current_learning_unit_year_id(
                learning_unit_to_edit, learning_unit_year_id)

            return HttpResponseRedirect(
                reverse('learning_unit', args=[learning_unit_year_id]))

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

    context['form'] = form
    return layout.render(request, 'learning_unit/edition.html', context)
 def test_edit_end_date(self):
     self.learning_unit.end_year = self.last_academic_year.year
     form_data = {"academic_year": self.current_academic_year.pk}
     form = LearningUnitEndDateForm(form_data,
                                    learning_unit=self.learning_unit)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data['academic_year'],
                      self.current_academic_year)
Example #4
0
def _update_or_create_suppression_proposal(request,
                                           learning_unit_year,
                                           proposal=None):
    person = get_object_or_404(Person, user=request.user)

    proposal_type = ProposalType.SUPPRESSION.name
    initial = _get_initial(learning_unit_year,
                           proposal,
                           person,
                           proposal_type=proposal_type)

    max_year = _get_max_year(learning_unit_year, proposal)

    form_end_date = LearningUnitEndDateForm(request.POST or None,
                                            learning_unit_year,
                                            max_year=max_year)
    form_proposal = ProposalLearningUnitForm(request.POST or None,
                                             person=person,
                                             instance=proposal,
                                             initial=initial)

    if form_end_date.is_valid() and form_proposal.is_valid():
        with transaction.atomic():
            form_proposal.save()

            # For the proposal, we do not update learning_unit_year
            form_end_date.save(update_learning_unit_year=False)

            display_success_messages(
                request,
                _("You proposed a modification of type {} for the learning unit {}."
                  ).format(_(proposal_type), learning_unit_year.acronym))

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

    context = get_learning_unit_identification_context(learning_unit_year.id,
                                                       person)
    context.update({
        'person': person,
        'form_end_date': form_end_date,
        'form_proposal': form_proposal,
        'experimental_phase': True
    })

    if learning_unit_year.get_partims_related().exists():
        display_warning_messages(request, _("The learning unit have partim"))

    if proposal:
        return render(request,
                      'learning_unit/proposal/update_suppression.html',
                      context)
    return render(request, 'learning_unit/proposal/create_suppression.html',
                  context)
Example #5
0
def _update_or_create_suppression_proposal(request,
                                           learning_unit_year,
                                           proposal=None):
    person = get_object_or_404(Person, user=request.user)

    proposal_type = ProposalType.SUPPRESSION.name
    initial = _get_initial(learning_unit_year,
                           proposal,
                           person,
                           proposal_type=proposal_type)

    max_year = _get_max_year(learning_unit_year, proposal)

    form_end_date = LearningUnitEndDateForm(request.POST or None,
                                            learning_unit_year,
                                            max_year=max_year)
    form_proposal = ProposalLearningUnitForm(request.POST or None,
                                             person=person,
                                             instance=proposal,
                                             initial=initial)

    if form_end_date.is_valid() and form_proposal.is_valid():
        with transaction.atomic():
            form_proposal.save()

            # For the proposal, we do not update learning_unit_year
            form_end_date.save(update_learning_unit_year=False)

            display_success_messages(
                request,
                _("You proposed a modification of type %(type)s for the learning unit %(acronym)s."
                  ) % {
                      'type': ProposalType.SUPPRESSION.value,
                      'acronym': learning_unit_year.acronym
                  })

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

    context = get_learning_unit_identification_context(learning_unit_year.id,
                                                       person)
    context.update({
        'person': person,
        'form_end_date': form_end_date,
        'form_proposal': form_proposal,
    })

    if proposal:
        return render(request,
                      'learning_unit/proposal/update_suppression.html',
                      context)
    return render(request, 'learning_unit/proposal/create_suppression.html',
                  context)
 def test_edit_end_date_send_dates_with_end_date_not_defined_and_periodicity_biennal_odd(
         self):
     self.learning_unit.periodicity = learning_unit_periodicity.BIENNIAL_ODD
     form = LearningUnitEndDateForm(
         None, learning_unit=self.learning_unit_year.learning_unit)
     self.assertEqual(list(form.fields['academic_year'].queryset),
                      self.list_of_odd_academic_years)
Example #7
0
def _update_or_create_suppression_proposal(request,
                                           person,
                                           learning_unit_year,
                                           proposal=None):
    type_proposal = ProposalType.SUPPRESSION.name
    initial = _get_initial(learning_unit_year, proposal, type_proposal, person)

    max_year = _get_max_year(learning_unit_year, proposal)

    form_end_date = LearningUnitEndDateForm(request.POST or None,
                                            learning_unit_year.learning_unit,
                                            max_year=max_year)
    form_proposal = ProposalLearningUnitForm(request.POST or None,
                                             person=person,
                                             instance=proposal,
                                             initial=initial)

    if form_end_date.is_valid() and form_proposal.is_valid():
        with transaction.atomic():
            form_proposal.save()

            # For the proposal, we do not update learning_unit_year
            form_end_date.save(update_learning_unit_year=False)

            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)

    context = get_learning_unit_identification_context(learning_unit_year.id,
                                                       person)
    context.update({
        'person': person,
        'form_end_date': form_end_date,
        'form_proposal': form_proposal,
        'experimental_phase': True
    })
    if proposal:
        return layout.render(request,
                             'learning_unit/proposal/update_suppression.html',
                             context)
    return layout.render(request,
                         'learning_unit/proposal/create_suppression.html',
                         context)
 def test_edit_end_date_send_dates_with_end_date_of_learning_unit_inferior_to_current_academic_year(self):
     self.learning_unit.end_year = self.oldest_academic_year.year
     form = LearningUnitEndDateForm(None, learning_unit_year=self.learning_unit_year)
     self.assertEqual(form.fields['academic_year'].disabled, True)
 def test_edit_end_date_send_dates_with_end_date_defined(self):
     self.learning_unit.end_year = self.last_academic_year.year
     form = LearningUnitEndDateForm(None, learning_unit_year=self.learning_unit_year)
     self.assertEqual(list(form.fields['academic_year'].queryset), self.list_of_academic_years_after_now)