示例#1
0
    def test_delete_partim_from_full(self):
        l_container_year = LearningContainerYearFactory(
            academic_year=self.academic_year)
        l_unit_year = LearningUnitYearFactory(
            subtype=learning_unit_year_subtypes.FULL,
            learning_container_year=l_container_year,
            learning_unit=LearningUnitFactory(start_year=1900),
            academic_year=l_container_year.academic_year)

        l_unit_partim_1 = LearningUnitYearFactory(
            subtype=learning_unit_year_subtypes.PARTIM,
            learning_container_year=l_container_year,
            learning_unit=LearningUnitFactory(start_year=1900),
            academic_year=l_container_year.academic_year)
        l_unit_partim_2 = LearningUnitYearFactory(
            subtype=learning_unit_year_subtypes.PARTIM,
            learning_container_year=l_container_year,
            learning_unit=LearningUnitFactory(start_year=1900),
            academic_year=l_container_year.academic_year)

        deletion.delete_from_given_learning_unit_year(l_unit_year)

        with self.assertRaises(ObjectDoesNotExist):
            LearningUnitYear.objects.get(id=l_unit_partim_1.id)

        with self.assertRaises(ObjectDoesNotExist):
            LearningUnitYear.objects.get(id=l_unit_partim_2.id)
示例#2
0
    def test_delete_learning_component_class(self):
        # Composant annualisé est associé à son composant et à son conteneur annualisé
        learning_component_year = LearningComponentYearFactory(acronym="/C",
                                                               comment="TEST")
        learning_container_year = learning_component_year.learning_unit_year.learning_container_year

        number_classes = 10
        for x in range(number_classes):
            LearningClassYearFactory(learning_component_year=learning_component_year)

        learning_unit_year = learning_component_year.learning_unit_year
        learning_unit_year.learning_unit.start_year = 1900
        learning_unit_year.subtype = learning_unit_year_subtypes.PARTIM
        learning_unit_year.save()

        msg = deletion.delete_from_given_learning_unit_year(learning_unit_year)

        msg_success = _("Learning unit %(acronym)s (%(academic_year)s) successfuly deleted.") % {
            'acronym': learning_unit_year.acronym,
            'academic_year': learning_unit_year.academic_year,
        }
        self.assertEqual(msg_success, msg.pop())

        self.assertEqual(LearningClassYear.objects.all().count(), 0)

        self.assertEqual(len(msg), number_classes)
        with self.assertRaises(ObjectDoesNotExist):
            LearningComponentYear.objects.get(id=learning_component_year.id)

        for classe in learning_component_year.learningclassyear_set.all():
            with self.assertRaises(ObjectDoesNotExist):
                LearningClassYear.objects.get(id=classe.id)

        # The learning_unit_container won't be deleted because the learning_unit_year is a partim
        self.assertEqual(learning_container_year, LearningContainerYear.objects.get(id=learning_container_year.id))
示例#3
0
    def test_delete_next_years(self):
        l_unit = LearningUnitFactory(start_year=1900)

        dict_learning_units = {}
        for year in range(2000, 2017):
            academic_year = AcademicYearFactory(year=year)
            dict_learning_units[year] = LearningUnitYearFactory(academic_year=academic_year, learning_unit=l_unit)

        year_to_delete = 2007
        msg = deletion.delete_from_given_learning_unit_year(dict_learning_units[year_to_delete])
        self.assertEqual(LearningUnitYear.objects.filter(academic_year__year__gte=year_to_delete,
                                                         learning_unit=l_unit).count(),
                         0)
        self.assertEqual(len(msg), 2017 - year_to_delete)
        self.assertEqual(l_unit.end_year, year_to_delete - 1)
示例#4
0
def cancel_proposal(proposal):
    results = {}
    if proposal.type == ProposalType.CREATION.name:
        learning_unit_year = proposal.learning_unit_year

        errors = list(business_deletion.check_can_delete_ignoring_proposal_validation(learning_unit_year).values())

        if errors:
            results = {ERROR: errors}
        else:
            results = {SUCCESS: business_deletion.delete_from_given_learning_unit_year(learning_unit_year)}
            delete_learning_unit_proposal(proposal, True)
    else:
        reinitialize_data_before_proposal(proposal)
        delete_learning_unit_proposal(proposal, False)

    return results
示例#5
0
    def test_delete_learning_container_year(self):
        learning_container_year = LearningContainerYearFactory()

        learning_unit_year_full = LearningUnitYearFactory(
            learning_container_year=learning_container_year,
            subtype=learning_unit_year_subtypes.FULL,
            learning_unit=LearningUnitFactory(start_year=1900),
            academic_year=learning_container_year.academic_year)
        learning_unit_year_partim = LearningUnitYearFactory(
            learning_container_year=learning_container_year,
            subtype=learning_unit_year_subtypes.PARTIM,
            learning_unit=LearningUnitFactory(start_year=1900),
            academic_year=learning_container_year.academic_year)
        learning_unit_year_to_delete = LearningUnitYearFactory(
            learning_container_year=learning_container_year,
            subtype=learning_unit_year_subtypes.PARTIM,
            learning_unit=LearningUnitFactory(start_year=1900),
            academic_year=learning_container_year.academic_year)

        deletion.delete_from_given_learning_unit_year(
            learning_unit_year_to_delete)

        with self.assertRaises(ObjectDoesNotExist):
            LearningUnitYear.objects.get(id=learning_unit_year_to_delete.id)
        self.assertEqual(
            learning_unit_year_partim,
            LearningUnitYear.objects.get(id=learning_unit_year_partim.id))
        self.assertEqual(
            learning_unit_year_full,
            LearningUnitYear.objects.get(id=learning_unit_year_full.id))
        self.assertEqual(
            learning_container_year,
            LearningContainerYear.objects.get(id=learning_container_year.id))

        deletion.delete_from_given_learning_unit_year(
            learning_unit_year_partim)

        with self.assertRaises(ObjectDoesNotExist):
            LearningUnitYear.objects.get(id=learning_unit_year_partim.id)
        self.assertEqual(
            learning_unit_year_full,
            LearningUnitYear.objects.get(id=learning_unit_year_full.id))
        self.assertEqual(
            learning_container_year,
            LearningContainerYear.objects.get(id=learning_container_year.id))

        deletion.delete_from_given_learning_unit_year(learning_unit_year_full)

        with self.assertRaises(ObjectDoesNotExist):
            LearningUnitYear.objects.get(id=learning_unit_year_full.id)

        with self.assertRaises(ObjectDoesNotExist):
            LearningContainerYear.objects.get(id=learning_container_year.id)
示例#6
0
文件: edition.py 项目: uclouvain/osis
def shorten_learning_unit(learning_unit_to_edit, new_academic_year):
    _check_shorten_partims(learning_unit_to_edit, new_academic_year)

    learning_unit_year_to_delete = LearningUnitYear.objects.filter(
        learning_unit=learning_unit_to_edit,
        academic_year__year__gte=new_academic_year.year + 1
    ).order_by('academic_year').first()

    if not learning_unit_year_to_delete:
        return []

    warning_msg = check_learning_unit_year_deletion(learning_unit_year_to_delete)
    if warning_msg:
        raise IntegrityError(list(warning_msg.values()))

    with transaction.atomic():
        result = delete_from_given_learning_unit_year(learning_unit_year_to_delete)
    return result
示例#7
0
def shorten_learning_unit(learning_unit_to_edit, new_academic_year):
    _check_shorten_partims(learning_unit_to_edit, new_academic_year)

    learning_unit_year_to_delete = LearningUnitYear.objects.filter(
        learning_unit=learning_unit_to_edit,
        academic_year__year__gte=new_academic_year.year +
        1).order_by('academic_year').first()

    if not learning_unit_year_to_delete:
        return []

    warning_msg = check_learning_unit_year_deletion(
        learning_unit_year_to_delete)
    if warning_msg:
        raise IntegrityError(list(warning_msg.values()))

    with transaction.atomic():
        result = delete_from_given_learning_unit_year(
            learning_unit_year_to_delete)
    return result
示例#8
0
    def test_delete_learning_unit_component_class(self):
        # Composant annualisé est associé à son composant et à son conteneur annualisé
        learning_component_year = LearningComponentYearFactory(acronym="/C",
                                                               comment="TEST")
        learning_container_year = learning_component_year.learning_container_year

        number_classes = 10
        for x in range(number_classes):
            LearningClassYearFactory(
                learning_component_year=learning_component_year)

        # Association du conteneur et de son composant dont les années académiques diffèrent l'une de l'autre
        learning_unit_component = LearningUnitComponentFactory(
            learning_component_year=learning_component_year)

        learning_unit_year = learning_unit_component.learning_unit_year
        learning_unit_year.learning_unit.start_year = 1900
        learning_unit_year.subtype = learning_unit_year_subtypes.PARTIM
        learning_unit_year.save()

        msg = deletion.delete_from_given_learning_unit_year(learning_unit_year)

        msg_success = _("learning_unit_successfuly_deleted")
        self.assertEqual(
            msg_success.format(acronym=learning_unit_year.acronym,
                               academic_year=learning_unit_year.academic_year),
            msg.pop())

        self.assertEqual(LearningClassYear.objects.all().count(), 0)

        self.assertEqual(len(msg), number_classes)
        with self.assertRaises(ObjectDoesNotExist):
            LearningUnitComponent.objects.get(id=learning_component_year.id)

        with self.assertRaises(ObjectDoesNotExist):
            LearningUnitComponent.objects.get(id=learning_unit_component.id)

        # The learning_unit_container won't be deleted because the learning_unit_year is a partim
        self.assertEqual(
            learning_container_year,
            LearningContainerYear.objects.get(id=learning_container_year.id))
示例#9
0
def cancel_proposal(learning_unit_proposal, author=None, send_mail=False):
    acronym = learning_unit_proposal.learning_unit_year.acronym
    academic_year = learning_unit_proposal.learning_unit_year.academic_year
    error_messages = []
    success_messages = []
    if learning_unit_proposal.type == ProposalType.CREATION.name:
        learning_unit_year = learning_unit_proposal.learning_unit_year
        error_messages.extend(
            business_deletion.check_can_delete_ignoring_proposal_validation(
                learning_unit_year))
        if not error_messages:
            success_messages.extend(
                business_deletion.delete_from_given_learning_unit_year(
                    learning_unit_year))
    else:
        reinitialize_data_before_proposal(learning_unit_proposal)
    delete_learning_unit_proposal(learning_unit_proposal)
    success_messages.append(
        _("success_cancel_proposal").format(acronym=acronym,
                                            academic_year=academic_year))
    if send_mail and author is not None:
        send_mail_util.send_mail_after_the_learning_unit_proposal_cancellation(
            [author], [learning_unit_proposal])
    return {SUCCESS: success_messages, ERROR: error_messages}