Esempio n. 1
0
    def test_when_differences_found_on_entity_component(self):
        next_academic_year = AcademicYear.objects.get(
            year=self.learning_unit_year_full.academic_year.year + 1)
        component = self._change_entity_component_value(next_academic_year, 24)

        expected_result = OrderedDict({
            next_academic_year: [
                _("The repartition volume of %(col_name)s has been already modified. "
                  "({%(new_value)s} instead of {%(current_value)s})") %
                {
                    'col_name':
                    component.learning_component_year.acronym + "-" +
                    component.entity_container_year.entity.most_recent_acronym,
                    'new_value':
                    component.repartition_volume,
                    'current_value':
                    '0.00'
                }
            ],
        })
        instance_luy_base_form = _instantiate_base_learning_unit_form(
            self.learning_unit_year_full, self.person)

        form = LearningUnitPostponementForm(
            self.person,
            self.learning_unit_year_full.academic_year,
            learning_unit_instance=instance_luy_base_form.
            learning_unit_instance,
            data=instance_luy_base_form.data)
        self.assertTrue(form.is_valid(), form.errors)
        result = form.consistency_errors
        self.assertDictEqual(result, expected_result)
Esempio n. 2
0
    def test_when_differences_found_on_components(self):
        next_academic_year = AcademicYear.objects.get(
            year=self.learning_unit_year_full.academic_year.year + 1)
        self._change_cm_component_value(next_academic_year, 12)

        expected_result = OrderedDict({
            next_academic_year: [
                _("%(col_name)s has been already modified. ({%(new_value)s} instead of {%(current_value)s})"
                  ) % {
                      'col_name':
                      _(LECTURING) + ' (' + _('hourly volume total annual') +
                      ')',
                      'current_value':
                      '-',
                      'new_value':
                      '12.00'
                  }
            ],
        })
        instance_luy_base_form = _instantiate_base_learning_unit_form(
            self.learning_unit_year_full, self.person)

        form = LearningUnitPostponementForm(
            self.person,
            self.learning_unit_year_full.academic_year,
            learning_unit_instance=instance_luy_base_form.
            learning_unit_instance,
            data=instance_luy_base_form.data)

        self.assertTrue(form.is_valid(), form.errors)
        result = form.consistency_errors
        self.assertDictEqual(result, expected_result)
Esempio n. 3
0
def update_learning_unit(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)

    learning_unit_full_instance = None
    if learning_unit_year.subtype == learning_unit_year_subtypes.PARTIM:
        learning_unit_full_instance = learning_unit_year.parent.learning_unit

    # TODO :: clean code ; end_postponement could be removed from kwargs in this following
    # LearningUnitPostponementForm instantiation + in the template form
    end_postponement = learning_unit_year.academic_year if not bool(int(request.POST.get('postponement', 1))) else None
    postponement_form = LearningUnitPostponementForm(
        person=person,
        start_postponement=learning_unit_year.academic_year,
        end_postponement=end_postponement,
        learning_unit_instance=learning_unit_year.learning_unit,
        learning_unit_full_instance=learning_unit_full_instance,
        data=request.POST or None,
        external=learning_unit_year.is_external(),
    )

    if postponement_form.is_valid():
        # Update current learning unit year
        _save_form_and_display_messages(request, postponement_form)
        return redirect('learning_unit', learning_unit_year_id=learning_unit_year_id)

    context = postponement_form.get_context()
    context["learning_unit_year"] = learning_unit_year
    context["is_update"] = True
    template = 'learning_unit/simple/update.html'

    return render(request, template, context)
Esempio n. 4
0
def create_learning_unit(request, academic_year_id):
    person = get_object_or_404(Person, user=request.user)
    if request.POST.get('academic_year'):
        academic_year_id = request.POST.get('academic_year')

    academic_year = get_object_or_404(AcademicYear, pk=academic_year_id)
    postponement_form = LearningUnitPostponementForm(
        person=person,
        start_postponement=academic_year,
        data=request.POST or None)
    if postponement_form.is_valid():
        return _save_and_redirect(postponement_form, request)

    return render(request, "learning_unit/simple/creation.html",
                  postponement_form.get_context())
Esempio n. 5
0
def create_partim_form(request, learning_unit_year_id):
    person = get_object_or_404(Person, user=request.user)
    learning_unit_year_full = get_object_or_404(LearningUnitYear,
                                                pk=learning_unit_year_id)

    postponement_form = LearningUnitPostponementForm(
        person=person,
        learning_unit_full_instance=learning_unit_year_full.learning_unit,
        start_postponement=learning_unit_year_full.academic_year,
        data=request.POST or None)

    if postponement_form.is_valid():
        return _save_and_redirect(postponement_form, request)

    context = postponement_form.get_context()
    context.update({'learning_unit_year': learning_unit_year_full})

    return render(request, "learning_unit/simple/creation_partim.html",
                  context)
Esempio n. 6
0
def get_external_learning_unit_creation_form(request, academic_year):
    person = get_object_or_404(Person, user=request.user)

    if request.POST.get('academic_year'):
        academic_year = request.POST.get('academic_year')

    academic_year = get_object_or_404(AcademicYear, pk=academic_year)

    postponement_form = LearningUnitPostponementForm(
        person=person,
        start_postponement=academic_year,
        data=request.POST or None,
        external=True,
    )

    if postponement_form.is_valid():
        return _save_and_redirect(postponement_form, request)

    return render(request, "learning_unit/external/create.html", postponement_form.get_context())