Example #1
0
    def test_extends_only_components_of_learning_unit_year(self):
        # Creating partim with components for the same learningContainerYear
        _create_learning_unit_year_with_components(self.learning_container_year,
                                                   create_lecturing_component=True,
                                                   create_pratical_component=True,
                                                   subtype=learning_unit_year_subtypes.PARTIM)

        inital_components_count = LearningComponentYear.objects.all().count()
        number_of_components = LearningUnitComponent.objects.filter(learning_unit_year=self.learning_unit_year).count()
        expected_count = inital_components_count + number_of_components
        next_year = self.academic_year.year + 1

        business_edition.duplicate_learning_unit_year(self.learning_unit_year, AcademicYearFactory(year=next_year))

        # assert components of partims are not duplicated too
        self.assertEqual(LearningComponentYear.objects.all().count(), expected_count)
Example #2
0
def extend_learning_units_until_last_academic_year(last_academic_year,
                                                   luys_to_duplicate):
    result = []
    errors = []
    for luy in luys_to_duplicate:
        try:
            with transaction.atomic():
                result.append(
                    duplicate_learning_unit_year(luy, last_academic_year))
        # General catch to be sure to not stop the rest of the duplication
        except (Error, ObjectDoesNotExist, MultipleObjectsReturned):
            errors.append(luy)

    return result, errors
Example #3
0
    def _compute_forms_to_insert_update_delete(self, data):
        if self._has_proposal(self.learning_unit_instance) and \
                (self.person.is_faculty_manager and not self.person.is_central_manager):
            proposal = ProposalLearningUnit.objects.filter(
                learning_unit_year__learning_unit=self.learning_unit_instance
            ).order_by('learning_unit_year__academic_year__year').first()
            max_postponement_year = proposal.learning_unit_year.academic_year.year
            ac_year_postponement_range = AcademicYear.objects.filter(
                year__gte=self.start_postponement.year,
                year__lt=proposal.learning_unit_year.academic_year.year
            )

            existing_learn_unit_years = LearningUnitYear.objects \
                .filter(academic_year__year__gte=self.start_postponement.year) \
                .filter(academic_year__year__lt=max_postponement_year) \
                .filter(learning_unit=self.learning_unit_instance) \
                .select_related('learning_container_year', 'learning_unit', 'academic_year') \
                .order_by('academic_year__year')
        else:
            max_postponement_year = self._compute_max_postponement_year()
            ac_year_postponement_range = AcademicYear.objects.min_max_years(
                self.start_postponement.year,
                max_postponement_year
            )
            existing_learn_unit_years = LearningUnitYear.objects.filter(
                academic_year__year__gte=self.start_postponement.year,
                learning_unit=self.learning_unit_instance,
            ).select_related(
                'learning_container_year', 'learning_unit', 'academic_year'
            ).order_by('academic_year__year')
        to_delete = to_update = to_insert = []

        if self.start_postponement.is_past:
            to_update = self._init_forms_in_past(existing_learn_unit_years, data)
        else:
            if self._is_update_action() and existing_learn_unit_years:
                to_delete = [
                    self._instantiate_base_form_as_update(luy, index_form=index)
                    for index, luy in enumerate(existing_learn_unit_years)
                    if luy.academic_year.year > max_postponement_year
                ]
                to_update = [
                    self._instantiate_base_form_as_update(luy, index_form=index, data=data)
                    for index, luy in enumerate(existing_learn_unit_years)
                    if luy.academic_year.year <= max_postponement_year
                ]
                existing_ac_years = [luy.academic_year for luy in existing_learn_unit_years]
                to_insert = []
                for index, ac_year in enumerate(ac_year_postponement_range):
                    if ac_year not in existing_ac_years:
                        new_learning_unit_year = duplicate_learning_unit_year(
                            existing_learn_unit_years[len(existing_learn_unit_years) - 1], ac_year
                        )
                        to_insert.append(self._instantiate_base_form_as_update(
                            new_learning_unit_year,
                            index_form=index,
                            data=data)
                        )
            else:
                to_insert = [
                    self._instantiate_base_form_as_insert(ac_year, data)
                    for index, ac_year in enumerate(ac_year_postponement_range)
                ]

        self._forms_to_delete = to_delete
        self._forms_to_upsert = to_update + to_insert