Example #1
0
    def _postpone_cms(old_egy, new_egy):
        TranslatedText.objects.filter(entity=entity_name.OFFER_YEAR,
                                      reference=str(new_egy.pk)).delete()

        for text in TranslatedText.objects.filter(
                entity=entity_name.OFFER_YEAR, reference=str(old_egy.pk)):
            update_related_object(text, "reference", str(new_egy.pk))
Example #2
0
    def _postpone_achievement(old_egy: EducationGroupYear, new_egy: EducationGroupYear):
        new_egy.educationgroupachievement_set.all().delete()

        for achievement in old_egy.educationgroupachievement_set.all():
            new_achievement = update_related_object(achievement, "education_group_year", new_egy)

            for detail in achievement.educationgroupdetailedachievement_set.all():
                update_related_object(detail, "education_group_achievement", new_achievement)
Example #3
0
    def _postpone_publication(old_egy: EducationGroupYear, new_egy: EducationGroupYear):
        new_egy.educationgrouppublicationcontact_set.all().delete()

        for publication in old_egy.educationgrouppublicationcontact_set.all():
            update_related_object(publication, "education_group_year", new_egy)

        new_egy.publication_contact_entity = old_egy.publication_contact_entity
        new_egy.save()
Example #4
0
def _duplicate_entity_container_year(new_lcy, new_academic_year):
    for entity_container_y in entity_container_year.search(learning_container_year=new_lcy.copied_from):
        entity_versions = EntityVersion.objects.entity(entity_container_y.entity)
        if not entity_versions.current(new_academic_year.end_date).exists():
            raise IntegrityError(
                _('The entity %(entity_acronym)s does not exist for the selected academic year %(academic_year)s') % {
                    'entity_acronym': entity_versions.last().acronym,
                    'academic_year': new_academic_year
                })
        update_related_object(entity_container_y, 'learning_container_year', new_lcy)
Example #5
0
    def _postpone_admission(old_egy: EducationGroupYear, new_egy: EducationGroupYear):
        if hasattr(new_egy, "admissioncondition"):
            new_egy.admissioncondition.delete()

        if not hasattr(old_egy, "admissioncondition"):
            return

        new_admission = update_related_object(old_egy.admissioncondition, "education_group_year", new_egy)

        for line in old_egy.admissioncondition.admissionconditionline_set.all():
            update_related_object(line, "admission_condition", new_admission)
Example #6
0
def _duplicate_entity_container_year(new_lcy, new_academic_year):
    for entity_container_y in entity_container_year.search(
            learning_container_year=new_lcy.copied_from):
        entity_versions = EntityVersion.objects.entity(
            entity_container_y.entity)
        if not entity_versions.current(new_academic_year.end_date).exists():
            raise IntegrityError(
                _('Entity_not_exist') % {
                    'entity_acronym': entity_versions.last().acronym,
                    'academic_year': new_academic_year
                })
        update_related_object(entity_container_y, 'learning_container_year',
                              new_lcy)
Example #7
0
    def postpone(self, instance=None):
        """
        We'll postpone first the group_element_years of the root,
        after that, we'll postponement recursively all the child branches and child leafs.
        """
        if not instance:
            instance = self.instance
            next_instance = self.instance_n1
        else:
            next_instance = self.get_instance_n1(instance)

        for gr in instance.groupelementyear_set.all():
            # For strange reasons, the education_group_year is not every times connected to a common education_group,
            # so we have to use the acronym to find the next group_element_year.
            new_gr = next_instance.groupelementyear_set.filter(
                child_branch__acronym=gr.child.acronym).first()
            if not new_gr:
                new_gr = update_related_object(gr, "parent", next_instance)

            if new_gr.child_leaf:
                self._postpone_child_leaf(gr, new_gr)
            else:
                self._postpone_child_branch(gr, new_gr)

            self.result.append(new_gr)

        return next_instance
Example #8
0
def _duplicate_learning_component_year(new_learn_unit_year,
                                       old_learn_unit_year):
    old_components = old_learn_unit_year.learningcomponentyear_set.all()
    for old_component in old_components:
        new_component = update_related_object(old_component,
                                              'learning_unit_year',
                                              new_learn_unit_year)
        _duplicate_learning_class_year(new_component)
Example #9
0
def _duplicate_learning_unit_component(new_component, new_learn_unit_year):
    for old_learn_unit_comp in learning_unit_component.search(
            a_learning_component_year=new_component.copied_from,
            a_learning_unit_year=new_learn_unit_year.copied_from):
        new_luc = update_related_object(old_learn_unit_comp,
                                        'learning_unit_year',
                                        new_learn_unit_year)
        new_luc.learning_component_year = new_component
        new_luc.save()
Example #10
0
def _duplicate_learning_unit_year(old_learn_unit_year, new_academic_year):
    duplicated_luy = update_related_object(old_learn_unit_year,
                                           'academic_year', new_academic_year)
    duplicated_luy.attribution_procedure = None
    duplicated_luy.learning_container_year = _duplicate_learning_container_year(
        duplicated_luy, new_academic_year)
    _duplicate_bibliography(duplicated_luy)
    _duplicate_cms_data(duplicated_luy)
    duplicated_luy.save()
    return duplicated_luy
Example #11
0
def _duplicate_learning_component_year(new_learn_container_year,
                                       new_learn_unit_year):
    for old_component in learning_component_year.find_by_learning_container_year(
            new_learn_container_year.copied_from):
        new_component = update_related_object(old_component,
                                              'learning_container_year',
                                              new_learn_container_year)
        _duplicate_learning_class_year(new_component)
        _duplicate_learning_unit_component(new_component, new_learn_unit_year)
        _duplicate_entity_component_year(new_component)
Example #12
0
def _duplicate_external(old_learning_unit_year, new_learning_unit_year):
    if old_learning_unit_year.is_external():
        try:
            return update_related_object(
                old_learning_unit_year.externallearningunityear,
                "learning_unit_year",
                new_learning_unit_year,
            )
        # Dirty data
        except LearningUnitYear.DoesNotExist:
            pass  # TODO Maybe we should return a error
Example #13
0
def _duplicate_external(old_learning_unit_year, new_learning_unit_year):
    if old_learning_unit_year.is_external():
        try:
            return update_related_object(
                old_learning_unit_year.externallearningunityear,
                "learning_unit_year",
                new_learning_unit_year,
            )
        # Dirty data
        except LearningUnitYear.DoesNotExist:
            pass  # TODO Maybe we should return a error
Example #14
0
def duplicate_learning_unit_year(old_learn_unit_year, new_academic_year):
    duplicated_luy = update_related_object(old_learn_unit_year,
                                           'academic_year', new_academic_year)
    duplicated_luy.attribution_procedure = None
    duplicated_luy.learning_container_year = _duplicate_learning_container_year(
        duplicated_luy, new_academic_year, old_learn_unit_year)
    _duplicate_teaching_material(duplicated_luy)
    _duplicate_cms_data(duplicated_luy)
    duplicated_luy.save()

    _duplicate_external(old_learn_unit_year, duplicated_luy)

    return duplicated_luy
Example #15
0
def _duplicate_learning_component_year(new_learn_container_year,
                                       new_learn_unit_year,
                                       old_learn_unit_year):
    old_learning_unit_components = learning_unit_component.find_by_learning_unit_year(old_learn_unit_year) \
        .select_related('learning_component_year')
    for learn_unit_component in old_learning_unit_components:
        old_component = learn_unit_component.learning_component_year
        new_component = update_related_object(old_component,
                                              'learning_container_year',
                                              new_learn_container_year)
        _duplicate_learning_class_year(new_component)
        _duplicate_learning_unit_component(new_component, new_learn_unit_year)
        _duplicate_entity_component_year(new_component)
Example #16
0
def _duplicate_entity_component_year(new_component, new_learn_container_year):
    for old_entity_comp_year in EntityComponentYear.objects.filter(learning_component_year=new_component.copied_from):
        old_entity_container = old_entity_comp_year.entity_container_year
        new_entity_container_year = EntityContainerYear.objects.get(
            learning_container_year=new_learn_container_year,
            entity=old_entity_container.entity,
            type=old_entity_container.type
        )

        new_entity_component_year = update_related_object(old_entity_comp_year,
                                                          'entity_container_year',
                                                          new_entity_container_year)
        new_entity_component_year.learning_component_year = new_component
        new_entity_component_year.save()
Example #17
0
def _duplicate_entity_component_year(new_component, new_learn_container_year):
    for old_entity_comp_year in EntityComponentYear.objects.filter(
            learning_component_year=new_component.copied_from):
        old_entity_container = old_entity_comp_year.entity_container_year
        new_entity_container_year = EntityContainerYear.objects.get(
            learning_container_year=new_learn_container_year,
            entity=old_entity_container.entity,
            type=old_entity_container.type)

        new_entity_component_year = update_related_object(
            old_entity_comp_year, 'entity_container_year',
            new_entity_container_year)
        new_entity_component_year.learning_component_year = new_component
        new_entity_component_year.save()
Example #18
0
def duplicate_learning_unit_year(old_learn_unit_year, new_academic_year):
    duplicated_luy = update_related_object(old_learn_unit_year, 'academic_year', new_academic_year)
    duplicated_luy.attribution_procedure = None
    duplicated_luy.learning_container_year = _duplicate_learning_container_year(
        duplicated_luy,
        new_academic_year,
        old_learn_unit_year
    )
    _duplicate_teaching_material(duplicated_luy)
    _duplicate_cms_data(duplicated_luy)
    duplicated_luy.save()

    _duplicate_external(old_learn_unit_year, duplicated_luy)

    return duplicated_luy
Example #19
0
def _get_or_create_container_year(new_learn_unit_year, new_academic_year):
    queryset = LearningContainerYear.objects.filter(
        academic_year=new_academic_year,
        learning_container=new_learn_unit_year.learning_container_year.learning_container
    )
    # Sometimes, the container already exists, we can directly use it and its entitycontaineryear
    if not queryset.exists():
        duplicated_lcy = update_related_object(new_learn_unit_year.learning_container_year,
                                               'academic_year', new_academic_year)
        duplicated_lcy.is_vacant = False
        duplicated_lcy.type_declaration_vacant = None

        _duplicate_entity_container_year(duplicated_lcy, new_academic_year)
    else:
        duplicated_lcy = queryset.get()
        duplicated_lcy.copied_from = new_learn_unit_year.learning_container_year
    return duplicated_lcy
Example #20
0
def _get_or_create_container_year(new_learn_unit_year, new_academic_year):
    queryset = LearningContainerYear.objects.filter(
        academic_year=new_academic_year,
        learning_container=new_learn_unit_year.learning_unit.learning_container
    )
    # Sometimes, the container already exists, we can directly use it and its entitycontaineryear
    if not queryset.exists():
        duplicated_lcy = update_related_object(
            new_learn_unit_year.learning_container_year, 'academic_year',
            new_academic_year)
        duplicated_lcy.is_vacant = False
        duplicated_lcy.type_declaration_vacant = None

        _duplicate_entity_container_year(duplicated_lcy, new_academic_year)
    else:
        duplicated_lcy = queryset.get()
        duplicated_lcy.copied_from = new_learn_unit_year.learning_container_year
    return duplicated_lcy
Example #21
0
    def _postpone_child(self, gr, next_instance):
        """ Determine if we have to postpone a leaf or a branch """
        new_gr = None

        if gr.child_branch:
            new_gr = next_instance.groupelementyear_set.filter(
                child_branch__education_group=gr.child.education_group
            ).first()

        if not new_gr:
            new_gr = update_related_object(gr, "parent", next_instance, commit_save=False)

        if new_gr.child_leaf:
            new_gr = self._postpone_child_leaf(gr, new_gr)
        else:
            new_gr = self._postpone_child_branch(gr, new_gr)
        new_gr.save()
        return new_gr
Example #22
0
    def _postpone_child(self, gr, next_instance):
        """ Determine if we have to postpone a leaf or a branch """
        new_gr = None

        if gr.child_branch:
            new_gr = next_instance.groupelementyear_set.filter(
                child_branch__education_group=gr.child.education_group
            ).first()

        if not new_gr:
            new_gr = update_related_object(gr, "parent", next_instance, commit_save=False)
            self.number_links_created += 1

        if new_gr.child_leaf:
            new_gr = self._postpone_child_leaf(gr, new_gr)
        else:
            new_gr = self._postpone_child_branch(gr, new_gr)
        new_gr.save()
        return new_gr
Example #23
0
def _duplicate_cms_data(duplicated_luy):
    previous_cms_data = TranslatedText.objects.filter(
        reference=duplicated_luy.copied_from.id)
    for item in previous_cms_data:
        update_related_object(item, 'reference', duplicated_luy.id)
Example #24
0
def _duplicate_learning_class_year(new_component):
    for old_learning_class in learning_class_year.find_by_learning_component_year(
            new_component.copied_from):
        update_related_object(old_learning_class, 'learning_component_year',
                              new_component)
Example #25
0
def _duplicate_learning_class_year(new_component):
    for old_learning_class in learning_class_year.find_by_learning_component_year(new_component.copied_from):
        update_related_object(old_learning_class, 'learning_component_year', new_component)
Example #26
0
def _duplicate_learning_component_year(new_learn_container_year, new_learn_unit_year, old_learn_unit_year):
    old_components = old_learn_unit_year.learningcomponentyear_set.all()
    for old_component in old_components:
        new_component = update_related_object(old_component, 'learning_unit_year', new_learn_unit_year)
        _duplicate_learning_class_year(new_component)
        _duplicate_entity_component_year(new_component, new_learn_container_year)
Example #27
0
def _duplicate_teaching_material(duplicated_luy):
    previous_teaching_material = mdl_base.teaching_material.find_by_learning_unit_year(duplicated_luy.copied_from)
    for material in previous_teaching_material:
        update_related_object(material, 'learning_unit_year', duplicated_luy)
Example #28
0
def _duplicate_cms_data(duplicated_luy):
    previous_cms_data = translated_text.find_by_reference(duplicated_luy.copied_from.id)
    for item in previous_cms_data:
        update_related_object(item, 'reference', duplicated_luy.id)
Example #29
0
def _duplicate_teaching_material(duplicated_luy):
    previous_teaching_material = mdl_base.teaching_material.find_by_learning_unit_year(
        duplicated_luy.copied_from)
    for material in previous_teaching_material:
        update_related_object(material, 'learning_unit_year', duplicated_luy)
Example #30
0
def _duplicate_bibliography(duplicated_luy):
    previous_bibliography = mdl_base.bibliography.find_by_learning_unit_year(
        duplicated_luy.copied_from)
    for bib in previous_bibliography:
        update_related_object(bib, 'learning_unit_year', duplicated_luy)
Example #31
0
def _duplicate_learning_class_year(new_component):
    learning_class_years = LearningClassYear.objects.filter(
        learning_component_year=new_component.copied_from).order_by("acronym")
    for old_learning_class in learning_class_years:
        update_related_object(old_learning_class, 'learning_component_year',
                              new_component)
Example #32
0
def _duplicate_cms_data(duplicated_luy):
    previous_cms_data = translated_text.find_by_reference(
        duplicated_luy.copied_from.id)
    for item in previous_cms_data:
        update_related_object(item, 'reference', duplicated_luy.id)
Example #33
0
    def _postpone_cms(old_egy, new_egy):
        TranslatedText.objects.filter(entity=entity_name.OFFER_YEAR, reference=str(new_egy.pk)).delete()

        for text in TranslatedText.objects.filter(entity=entity_name.OFFER_YEAR, reference=str(old_egy.pk)):
            update_related_object(text, "reference", str(new_egy.pk))