Example #1
0
    def test_disabled_internship_subtype_in_case_of_container_type_different_than_internship(self):
        form = LearningUnitModificationForm(person=self.person, initial=self.initial_data)

        self.assertTrue(form.fields["internship_subtype"].disabled)

        initial_data_with_internship_container_type = self.form_data.copy()
        initial_data_with_internship_container_type["container_type"] = learning_container_year_types.INTERNSHIP

        form = LearningUnitModificationForm(person=self.person, initial=initial_data_with_internship_container_type)

        self.assertFalse(form.fields["internship_subtype"].disabled)
Example #2
0
    def test_entity_does_not_exist_for_lifetime_of_learning_unit_with_no_planned_end(self):
        an_other_entity = EntityFactory(organization=self.organization)
        an_other_entity_version = EntityVersionFactory(
            entity=an_other_entity, entity_type=entity_type.SCHOOL, parent=None,
            end_date=self.current_academic_year.end_date - datetime.timedelta(days=5),
            start_date=datetime.date.today() - datetime.timedelta(days=5))
        PersonEntityFactory(person=self.person, entity=an_other_entity)

        form_data_with_invalid_requirement_entity = self.form_data.copy()
        form_data_with_invalid_requirement_entity["requirement_entity"] = str(an_other_entity_version.id)
        form = LearningUnitModificationForm(form_data_with_invalid_requirement_entity,
                                            person=self.person, initial=self.initial_data)
        self.assertFalse(form.is_valid())
Example #3
0
    def test_when_requirement_and_attribution_entities_are_different_for_disseration_and_internship_subtype(self):
        an_other_entity = EntityFactory(organization=self.organization)
        an_other_entity_version = EntityVersionFactory(entity=an_other_entity, entity_type=entity_type.SCHOOL,
                                                       parent=None, end_date=None,
                                                       start_date=datetime.date.today() - datetime.timedelta(days=5))
        form_data_with_different_allocation_entity = self.form_data.copy()
        form_data_with_different_allocation_entity["allocation_entity"] = str(an_other_entity_version.id)

        for container_type in (learning_container_year_types.DISSERTATION, learning_container_year_types.INTERNSHIP):
            initial_data_with_specific_container_type = self.initial_data.copy()
            initial_data_with_specific_container_type["container_type"] = container_type
            form = LearningUnitModificationForm(form_data_with_different_allocation_entity,
                                                person=self.person, initial=initial_data_with_specific_container_type)
            self.assertFalse(form.is_valid())
    def test_disabled_internship_subtype_in_case_of_container_type_different_than_internship(
            self):
        form = LearningUnitModificationForm(
            person=self.person,
            learning_unit_year_instance=self.learning_unit_year)

        self.assertTrue(form.fields["internship_subtype"].disabled)

        self.learning_unit_year.learning_container_year.container_type = learning_container_year_types.INTERNSHIP

        form = LearningUnitModificationForm(
            person=self.person,
            learning_unit_year_instance=self.learning_unit_year)

        self.assertFalse(form.fields["internship_subtype"].disabled)
Example #5
0
 def test_partim_can_modify_periodicity(self):
     initial_data_with_subtype_partim = self.initial_data.copy()
     initial_data_with_subtype_partim["subtype"] = learning_unit_year_subtypes.PARTIM
     form = LearningUnitModificationForm(learning_unit_year_instance=self.learning_unit_year_partim_1,
                                         person=self.person,
                                         initial=initial_data_with_subtype_partim)
     self.assertFalse(form.fields["periodicity"].disabled)
Example #6
0
 def test_do_not_set_minimum_credits_for_full_learning_unit_year_if_no_partims(self):
     learning_unit_year_with_no_partims = LearningUnitYearFactory(academic_year=self.current_academic_year,
                                                                  learning_unit__periodicity=ANNUAL,
                                                                  subtype=FULL)
     form = LearningUnitModificationForm(person=self.person,
                                         learning_unit_year_instance=learning_unit_year_with_no_partims,
                                         initial=self.initial_data)
     self.assertEqual(form.fields["credits"].min_value, None)
Example #7
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)
    form = LearningUnitModificationForm(
        request.POST or None,
        learning_unit_year_instance=learning_unit_year,
        person=person)

    if form.is_valid():
        _save_form_and_display_messages(request, form)
        _check_credits(request, learning_unit_year.parent, form)
        return redirect("learning_unit",
                        learning_unit_year_id=learning_unit_year.id)

    context = {"learning_unit_year": learning_unit_year, "form": form}
    return layout.render(request, 'learning_unit/modification.html', context)
    def test_when_partim_active_but_modify_parent_to_inactive(self):
        # Set status to parent inactive
        form_data_parent_with_status_inactive = self.form_data.copy()
        form_data_parent_with_status_inactive['status'] = False

        # Set status to partim active
        self.learning_unit_year_partim_1.status = True
        self.learning_unit_year_partim_1.save()

        form = LearningUnitModificationForm(
            form_data_parent_with_status_inactive,
            person=self.person,
            end_date=self.current_academic_year.end_date,
            learning_unit_year_instance=self.learning_unit_year)
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors['status'],
            [_('The parent must be active because there are partim active')])
    def test_disabled_fields_in_case_of_learning_unit_of_type_full(self):

        form = LearningUnitModificationForm(
            person=self.person,
            learning_unit_year_instance=self.learning_unit_year)
        disabled_fields = ("first_letter", "acronym", "academic_year",
                           "container_type", "subtype")
        for field in disabled_fields:
            self.assertTrue(form.fields[field].disabled)
Example #10
0
 def test_disabled_fields_in_case_of_learning_unit_of_type_partim(self):
     initial_data_with_subtype_partim = self.initial_data.copy()
     initial_data_with_subtype_partim["subtype"] = learning_unit_year_subtypes.PARTIM
     form = LearningUnitModificationForm(person=self.person, initial=initial_data_with_subtype_partim)
     disabled_fields = ('first_letter', 'acronym', 'common_title', 'common_title_english', 'requirement_entity',
                        'allocation_entity', 'language', 'periodicity', 'campus', 'container_type', "academic_year",
                        'internship_subtype', 'additional_requirement_entity_1', 'additional_requirement_entity_2',
                        'is_vacant', 'team', 'type_declaration_vacant', 'attribution_procedure', "subtype")
     for field in disabled_fields:
         self.assertTrue(form.fields[field].disabled)
Example #11
0
def modify_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)
    initial_data = compute_learning_unit_modification_form_initial_data(
        learning_unit_year)
    form = LearningUnitModificationForm(
        request.POST or None,
        learning_unit_year_instance=learning_unit_year,
        person=person,
        initial=initial_data)
    if form.is_valid():
        entities_data = form.get_entities_data()
        lu_type_full_data = form.get_data_for_learning_unit()

        try:
            postponement = bool(int(request.POST.get('postponement', 1)))

            update_learning_unit_year_with_report(learning_unit_year,
                                                  lu_type_full_data,
                                                  postponement)
            update_learning_unit_year_entities_with_report(
                learning_unit_year, entities_data, postponement)

            display_success_messages(request,
                                     _("success_modification_learning_unit"))

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

        except IntegrityError:
            display_error_messages(request,
                                   _("error_modification_learning_unit"))

    context = {"learning_unit_year": learning_unit_year, "form": form}
    return layout.render(request, 'learning_unit/modification.html', context)
    def test_disabled_fields_in_case_of_learning_unit_of_type_partim(self):

        form = LearningUnitModificationForm(
            person=self.person,
            learning_unit_year_instance=self.learning_unit_year_partim_1)
        disabled_fields = ('first_letter', 'acronym', 'common_title',
                           'common_title_english', 'requirement_entity',
                           'allocation_entity', 'language', 'campus',
                           'container_type', "academic_year",
                           'internship_subtype',
                           'additional_requirement_entity_1',
                           'additional_requirement_entity_2', 'is_vacant',
                           'team', 'type_declaration_vacant',
                           'attribution_procedure', "subtype", "status")
        for field in form.fields:
            if field in disabled_fields:
                self.assertTrue(form.fields[field].disabled, field)
            else:
                self.assertFalse(form.fields[field].disabled, field)
 def test_deactivated_fields_in_learning_unit_modification_form(self):
     form = LearningUnitModificationForm(
         person=self.person,
         learning_unit_year_instance=self.learning_unit_year)
     self.assertFalse(form.fields["common_title"].disabled)
     self.assertFalse(form.fields["common_title_english"].disabled)
     self.assertFalse(form.fields["specific_title"].disabled)
     self.assertFalse(form.fields["specific_title_english"].disabled)
     self.assertFalse(form.fields["faculty_remark"].disabled)
     self.assertFalse(form.fields["other_remark"].disabled)
     self.assertFalse(form.fields["campus"].disabled)
     self.assertFalse(form.fields["status"].disabled)
     self.assertFalse(form.fields["credits"].disabled)
     self.assertFalse(form.fields["language"].disabled)
     self.assertFalse(form.fields["requirement_entity"].disabled)
     self.assertFalse(form.fields["allocation_entity"].disabled)
     self.assertFalse(
         form.fields["additional_requirement_entity_2"].disabled)
     self.assertFalse(form.fields["is_vacant"].disabled)
     self.assertFalse(form.fields["type_declaration_vacant"].disabled)
     self.assertFalse(form.fields["attribution_procedure"].disabled)
     self.assertTrue(form.fields["subtype"].disabled)
Example #14
0
 def test_set_max_credits(self):
     form = LearningUnitModificationForm(learning_unit_year_instance=self.learning_unit_year_partim_1,
                                         person=self.person,
                                         initial=self.initial_data)
     self.assertEqual(form.fields["credits"].max_value, self.learning_unit_year.credits)
 def test_valid_form_with_faculty_manager(self):
     form = LearningUnitModificationForm(
         self.form_data,
         person=self.person,
         learning_unit_year_instance=self.learning_unit_year)
     self.assertTrue(form.is_valid(), form.errors)
Example #16
0
 def test_set_minimum_credits_for_full_learning_unit_year(self):
     form = LearningUnitModificationForm(person=self.person, learning_unit_year_instance=self.learning_unit_year,
                                         initial=self.initial_data)
     self.assertEqual(form.fields["credits"].min_value, self.learning_unit_year_partim_1.credits)
 def test_set_status_value(self):
     form = LearningUnitModificationForm(
         learning_unit_year_instance=self.learning_unit_year_partim_1,
         person=self.person)
     self.assertEqual(form.fields["status"].initial, False)
     self.assertTrue(form.fields["status"].disabled)
Example #18
0
 def test_valid_form(self):
     form = LearningUnitModificationForm(self.form_data, initial=self.initial_data, person=self.person)
     self.assertTrue(form.is_valid())