Exemple #1
0
    def test_folder_creation(self):
        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        proposal_folder_created = proposal_folder.find_by_entity_and_folder_id(self.entity_version.entity, 1)

        self.assertTrue(proposal_folder_created)
Exemple #2
0
    def test_invalid_form(self):
        del self.form_data['requirement_entity']

        form = LearningUnitProposalModificationForm(self.form_data,
                                                    self.person)
        with self.assertRaises(ValueError):
            form.save(self.learning_unit_year, PROPOSAL_TYPE, PROPOSAL_STATE)
Exemple #3
0
    def test_with_all_entities_set(self):
        today = datetime.date.today()
        entity_1 = EntityFactory(organization=OrganizationFactory(type=organization_type.MAIN))
        additional_entity_version_1 = EntityVersionFactory(entity_type=entity_type.SCHOOL, start_date=today,
                                                           end_date=today.replace(year=today.year + 1),
                                                           entity=entity_1)
        entity_2 = EntityFactory(organization=OrganizationFactory(type=organization_type.MAIN))
        additional_entity_version_2 = EntityVersionFactory(entity_type=entity_type.SCHOOL, start_date=today,
                                                           end_date=today.replace(year=today.year + 1),
                                                           entity=entity_2)
        self.form_data["allocation_entity"] = self.entity_version.id
        self.form_data["additional_entity_1"] = additional_entity_version_1.id
        self.form_data["additional_entity_2"] = additional_entity_version_2.id

        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        entities_by_type = \
            entity_container_year.find_entities_grouped_by_linktype(self.learning_unit_year.learning_container_year)

        expected_entities = {
            entity_container_year_link_type.REQUIREMENT_ENTITY: self.entity_version.entity,
            entity_container_year_link_type.ALLOCATION_ENTITY: self.entity_version.entity,
            entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: additional_entity_version_1.entity,
            entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: additional_entity_version_2.entity
        }
        self.assertDictEqual(entities_by_type, expected_entities)
Exemple #4
0
    def test_learning_unit_update(self):
        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        self.learning_unit_year.refresh_from_db()

        self.assertEqual(self.learning_unit_year.learning_unit.periodicity, self.form_data['periodicity'])
Exemple #5
0
    def test_requirement_entity(self):
        form = LearningUnitProposalModificationForm(self.form_data,
                                                    self.person)
        form.save(self.learning_unit_year, PROPOSAL_TYPE, PROPOSAL_STATE)

        self.entity_container_year.refresh_from_db()
        self.assertEqual(self.entity_container_year.entity,
                         self.entity_version.entity)
Exemple #6
0
    def test_folder_reuse(self):
        folder = ProposalFolderFactory(entity=self.entity_version.entity, folder_id=1)

        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        a_proposal_learning_unt = proposal_learning_unit.find_by_learning_unit_year(self.learning_unit_year)
        self.assertEqual(a_proposal_learning_unt.folder, folder)
Exemple #7
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 #8
0
    def test_modify_learning_container_subtype(self):
        self.form_data["container_type"] = learning_container_year_types.INTERNSHIP
        self.form_data["internship_subtype"] = internship_subtypes.TEACHING_INTERNSHIP

        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        self.learning_unit_year.refresh_from_db()

        self.assertEqual(self.learning_unit_year.learning_container_year.container_type,
                         learning_container_year_types.INTERNSHIP)
        self.assertEqual(self.learning_unit_year.internship_subtype, internship_subtypes.TEACHING_INTERNSHIP)
Exemple #9
0
    def test_learning_container_update(self):
        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        self.learning_unit_year.refresh_from_db()
        learning_container_year = self.learning_unit_year.learning_container_year

        self.assertEqual(learning_container_year.acronym,
                         "{}{}".format(self.form_data['first_letter'], self.form_data['acronym']))
        self.assertEqual(learning_container_year.title, self.form_data['title'])
        self.assertEqual(learning_container_year.title_english, self.form_data['title_english'])
        self.assertEqual(learning_container_year.language, self.language)
        self.assertEqual(learning_container_year.campus, self.campus)
Exemple #10
0
    def test_learning_unit_year_update(self):
        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        self.learning_unit_year.refresh_from_db()

        self.assertEqual(self.learning_unit_year.acronym,
                         "{}{}".format(self.form_data['first_letter'], self.form_data['acronym']))
        self.assertEqual(self.learning_unit_year.title, self.form_data['title'])
        self.assertEqual(self.learning_unit_year.title_english, self.form_data['title_english'])
        self.assertFalse(self.learning_unit_year.status)
        self.assertEqual(self.learning_unit_year.credits, Decimal(self.form_data['credits']))
        self.assertEqual(self.learning_unit_year.quadrimester, self.form_data['quadrimester'])
Exemple #11
0
 def test_learning_unit_year_update(self):
     form = LearningUnitProposalModificationForm(self.form_data,
                                                 person=self.person)
     form.save(self.learning_unit_year, PROPOSAL_TYPE, PROPOSAL_STATE)
     self.learning_unit_year.refresh_from_db()
     self._assert_acronym_has_changed_in_proposal()
     self._assert_common_titles_stored_in_container()
     self.assertFalse(self.learning_unit_year.status)
     self.assertEqual(self.learning_unit_year.credits,
                      Decimal(self.form_data['credits']))
     self.assertEqual(self.learning_unit_year.quadrimester,
                      self.form_data['quadrimester'])
     self.assertEqual(self.learning_unit_year.specific_title,
                      self.form_data["specific_title"])
     self.assertEqual(self.learning_unit_year.specific_title_english,
                      self.form_data["specific_title_english"])
Exemple #12
0
    def test_when_setting_additional_entity_to_none(self):
        EntityContainerYearFactory(
            learning_container_year=self.learning_unit_year.
            learning_container_year,
            type=entity_container_year_link_type.ALLOCATION_ENTITY)
        EntityContainerYearFactory(learning_container_year=self.
                                   learning_unit_year.learning_container_year,
                                   type=entity_container_year_link_type.
                                   ADDITIONAL_REQUIREMENT_ENTITY_1)
        form = LearningUnitProposalModificationForm(self.form_data,
                                                    self.person)
        form.save(self.learning_unit_year, PROPOSAL_TYPE, PROPOSAL_STATE)

        with self.assertRaises(ObjectDoesNotExist):
            EntityContainerYear.objects.get(
                learning_container_year=self.learning_unit_year.
                learning_container_year,
                type=entity_container_year_link_type.
                ADDITIONAL_REQUIREMENT_ENTITY_1)
Exemple #13
0
    def test_creation_proposal_learning_unit(self):
        initial_data_expected = {
            "learning_container_year": {
                "id": self.learning_unit_year.learning_container_year.id,
                "acronym": self.learning_unit_year.acronym,
                "title": self.learning_unit_year.title,
                "title_english": self.learning_unit_year.title_english,
                "container_type": self.learning_unit_year.learning_container_year.container_type,
                "campus": self.learning_unit_year.learning_container_year.campus.id,
                "language": self.learning_unit_year.learning_container_year.language.id,
                "in_charge": self.learning_unit_year.learning_container_year.in_charge
            },
            "learning_unit_year": {
                "id": self.learning_unit_year.id,
                "acronym": self.learning_unit_year.acronym,
                "title": self.learning_unit_year.title,
                "title_english": self.learning_unit_year.title_english,
                "internship_subtype": self.learning_unit_year.internship_subtype,
                "credits": self.learning_unit_year.credits,
                "quadrimester": self.learning_unit_year.quadrimester,
            },
            "learning_unit": {
                "id": self.learning_unit_year.learning_unit.id,
                "periodicity": self.learning_unit_year.learning_unit.periodicity
            },
            "entities": {
                entity_container_year_link_type.REQUIREMENT_ENTITY: self.entity_container_year.entity.id,
                entity_container_year_link_type.ALLOCATION_ENTITY: None,
                entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: None,
                entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: None
            }
        }

        form = LearningUnitProposalModificationForm(self.form_data)
        form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)

        a_proposal_learning_unt = proposal_learning_unit.find_by_learning_unit_year(self.learning_unit_year)

        self.assertEqual(a_proposal_learning_unt.type, PROPOSAL_TYPE)
        self.assertEqual(a_proposal_learning_unt.state, PROPOSAL_STATE)
        self.assertEqual(a_proposal_learning_unt.author, self.person)

        self.assertDictEqual(a_proposal_learning_unt.initial_data, initial_data_expected)
Exemple #14
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
        })
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 #17
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
        })
Exemple #18
0
 def test_learning_unit_proposal_form_get_as_central_manager(self):
     self.person.user.groups.add(
         Group.objects.get(name=CENTRAL_MANAGER_GROUP))
     form = LearningUnitProposalModificationForm(self.form_data,
                                                 person=self.person)
     self.assertFalse(form.fields['state'].disabled)
Exemple #19
0
    def test_invalid_form(self):
        del self.form_data['academic_year']

        form = LearningUnitProposalModificationForm(self.form_data)
        with self.assertRaises(ValueError):
            form.save(self.learning_unit_year, self.person, PROPOSAL_TYPE, PROPOSAL_STATE)