Example #1
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)
Example #2
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)
    def test_save_with_all_luy_to_create_partim_with_end_year(
            self, mock_baseform_save):
        self.instance_luy_partim_form.data.update({
            'end_year':
            self.learning_unit_year_full.academic_year.year + 2,
            'component-TOTAL_FORMS':
            2,
            'component-INITIAL_FORMS':
            0,
            'component-MAX_NUM_FORMS':
            2,
            'component-0-hourly_volume_total_annual':
            20,
            'component-0-hourly_volume_partial_q1':
            10,
            'component-0-hourly_volume_partial_q2':
            10,
        })

        form = LearningUnitPostponementForm(
            self.person,
            self.learning_unit_year_full.academic_year,
            learning_unit_full_instance=self.learning_unit_year_full.
            learning_unit,
            data=self.instance_luy_partim_form.data)

        self.assertEqual(len(form._forms_to_upsert), 3)

        form.save()
        self.assertEqual(mock_baseform_save.call_count, 3)
Example #4
0
    def test_save_with_all_luy_to_create_partim_with_end_year(
            self, mock_baseform_save):
        LearningUnitYear.objects.filter(
            learning_unit=self.learn_unit_structure.learning_unit_partim,
            academic_year__year__gt=self.current_academic_year.year).delete()

        instance_luy_base_form = _instantiate_base_learning_unit_form(
            self.learning_unit_year_partim, self.person)
        instance_luy_base_form.data[
            'end_year'] = self.learning_unit_year_full.academic_year.year + 2
        instance_luy_base_form.data['form-TOTAL_FORMS'] = 2
        instance_luy_base_form.data['form-INITIAL_FORMS'] = 0
        instance_luy_base_form.data['form-MAX_NUM_FORMS'] = 2
        instance_luy_base_form.data['form-0-hourly_volume_total_annual'] = 20
        instance_luy_base_form.data['form-0-hourly_volume_partial_q1'] = 10
        instance_luy_base_form.data['form-0-hourly_volume_partial_q2'] = 10

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

        self.assertEqual(len(form._forms_to_upsert), 3)

        form.save()
        self.assertEqual(mock_baseform_save.call_count, 3)
Example #5
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)
    def test_save_with_all_luy_to_create_partim(self, mock_baseform_save):
        form = LearningUnitPostponementForm(
            self.person,
            self.learning_unit_year_full.academic_year,
            learning_unit_full_instance=self.learning_unit_year_full.
            learning_unit,
            data=self.instance_luy_partim_form.data)

        self.assertEqual(len(form._forms_to_upsert), 7)
        form.save()
        self.assertEqual(mock_baseform_save.call_count, 7)
Example #7
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())
Example #8
0
    def test_save_with_all_luy_to_create_partim(self, mock_baseform_save):
        LearningUnitYear.objects.filter(
            learning_unit=self.learn_unit_structure.learning_unit_partim,
            academic_year__year__gt=self.current_academic_year.year).delete()
        instance_luy_base_form = _instantiate_base_learning_unit_form(
            self.learning_unit_year_partim, self.person)
        form = LearningUnitPostponementForm(
            self.person,
            self.learning_unit_year_full.academic_year,
            learning_unit_full_instance=self.learning_unit_year_full.
            learning_unit,
            data=instance_luy_base_form.data)

        self.assertEqual(len(form._forms_to_upsert), 7)

        form.save()
        self.assertEqual(mock_baseform_save.call_count, 7)
Example #9
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)
Example #10
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())
Example #11
0
def _instanciate_postponement_form(person,
                                   start_postponement,
                                   end_postponement=None,
                                   learning_unit_instance=None,
                                   data=None,
                                   learning_unit_full_instance=None):
    return LearningUnitPostponementForm(
        person,
        start_postponement,
        learning_unit_instance=learning_unit_instance,
        learning_unit_full_instance=learning_unit_full_instance,
        end_postponement=end_postponement,
        data=data)