Beispiel #1
0
def populate_cae_situations_and_career_stages(session):
    """
    Populate the database with default CAE situation options and career stages
    """
    # Populate CAE situations
    from autonomie.models.user.userdatas import CaeSituationOption
    query = session.query(CaeSituationOption)
    if query.count() == 0:
        situation_cand = CaeSituationOption(label=u"Candidat", order=0)
        situation_conv = CaeSituationOption(label=u"En convention",
                                            is_integration=True,
                                            order=1)
        situation_es = CaeSituationOption(label=u"Entrepreneur salarié",
                                          is_integration=True,
                                          order=2)
        situation_out = CaeSituationOption(label=u"Sortie", order=3)
        session.add(situation_cand)
        session.add(situation_conv)
        session.add(situation_es)
        session.add(situation_out)
        session.flush()
    # Populate Career Stages
    from autonomie.models.career_stage import CareerStage
    if CareerStage.query().count() == 0:
        for active, name, cae_situation_id, stage_type in (
            (True, "Diagnostic", None, None),
            (True, "Contrat CAPE", situation_conv.id, "entry"),
            (True, "Contrat CESA", situation_es.id, "contract"),
            (True, "Avenant contrat", None, "amendment"),
            (True, "Sortie", situation_out.id, "exit"),
        ):
            session.add(
                CareerStage(
                    active=active,
                    name=name,
                    cae_situation_id=cae_situation_id,
                    stage_type=stage_type,
                ))
        session.flush()
Beispiel #2
0
    def get_career_path_by_stages(self):
        """
        Collect CareerPath associated to this instance and stores them by stage
        name

        :returns: A dict {'stage': [List of ordered CareerPath]}
        :rtype: dict
        """
        from autonomie.models.career_path import CareerPath
        from autonomie.models.career_stage import CareerStage
        result = {}
        for stage in CareerStage.query():
            result[stage.name] = CareerPath.query(
                self.id).filter_by(career_stage_id=stage.id).all()
        return result
    def get_career_path_by_stages(self):
        """
        Collect CareerPath associated to this instance and stores them by stage
        name

        :returns: A dict {'stage': [List of ordered CareerPath]}
        :rtype: dict
        """
        from autonomie.models.career_path import CareerPath
        from autonomie.models.career_stage import CareerStage
        result = {}
        for stage in CareerStage.query():
            result[stage.name] = CareerPath.query(self.id).filter_by(
                career_stage_id=stage.id
            ).all()
        return result
def populate_cae_situations_and_career_stages(session):
    """
    Populate the database with default CAE situation options and career stages
    """
    # Populate CAE situations
    from autonomie.models.user.userdatas import CaeSituationOption
    query = session.query(CaeSituationOption)
    if query.count() == 0:
        situation_cand = CaeSituationOption(label=u"Candidat", order=0)
        situation_conv = CaeSituationOption(label=u"En convention", is_integration=True, order=1)
        situation_es = CaeSituationOption(label=u"Entrepreneur salarié", is_integration=True, order=2)
        situation_out = CaeSituationOption(label=u"Sortie", order=3)
        session.add(situation_cand)
        session.add(situation_conv)
        session.add(situation_es)
        session.add(situation_out)
        session.flush()
    # Populate Career Stages
    from autonomie.models.career_stage import CareerStage
    if CareerStage.query().count() == 0:
        for active, name, cae_situation_id, stage_type in (
            (True, "Diagnostic", None, None),
            (True, "Contrat CAPE", situation_conv.id, "entry"),
            (True, "Contrat CESA", situation_es.id, "contract"),
            (True, "Avenant contrat", None, "amendment"),
            (True, "Sortie", situation_out.id, "exit"),
        ):
            session.add(
                CareerStage(
                    active=active,
                    name=name,
                    cae_situation_id=cae_situation_id,
                    stage_type=stage_type,
                )
            )
        session.flush()
def populate_default_datas():
    """
    Populate the database with missing default entries if needed
    """
    from autonomie.models.user.userdatas import CaeSituationOption
    from autonomie.models.career_stage import CareerStage
    from autonomie.models.career_path import TypeContratOption
    session = DBSESSION()
    # Populate contract types
    if session.query(TypeContratOption).filter(
            TypeContratOption.label == "CDD").count() == 0:
        session.add(TypeContratOption(label=u"CDD", order=0))
    if session.query(TypeContratOption).filter(
            TypeContratOption.label == "CDI").count() == 0:
        session.add(TypeContratOption(label=u"CDI", order=0))
    if session.query(TypeContratOption).filter(
            TypeContratOption.label == "CESA").count() == 0:
        session.add(TypeContratOption(label=u"CESA", order=0))
    session.flush()
    # Populate CAE situations
    situation_cand = session.query(CaeSituationOption).filter(
        CaeSituationOption.label == "Candidat").first()
    if situation_cand is None:
        situation_cand = CaeSituationOption(label=u"Candidat", order=0)
        session.add(situation_cand)
    situation_conv = session.query(CaeSituationOption).filter(
        CaeSituationOption.label == "En convention").first()
    if situation_conv is None:
        situation_conv = CaeSituationOption(label=u"En convention",
                                            is_integration=True)
        session.add(situation_conv)
    situation_es = session.query(CaeSituationOption).filter(
        CaeSituationOption.label == "Entrepreneur salarié").first()
    if situation_es is None:
        situation_es = CaeSituationOption(label=u"Entrepreneur salarié",
                                          is_integration=True)
        session.add(situation_es)
    situation_out = session.query(CaeSituationOption).filter(
        CaeSituationOption.label == "Sortie").first()
    if situation_out is None:
        situation_out = CaeSituationOption(label=u"Sortie")
        session.add(situation_out)
    session.flush()
    # Populate Career Stages
    if CareerStage.query().count() == 0:
        stage_diag = CareerStage(
            active=True,
            name="Diagnostic",
            cae_situation_id=None,
            stage_type=None,
        )
        stage_cape = CareerStage(
            active=True,
            name="Contrat CAPE",
            cae_situation_id=situation_conv.id,
            stage_type="entry",
        )
        stage_dpae = CareerStage(
            active=True,
            name="Contrat DPAE",
            cae_situation_id=None,
            stage_type=None,
        )
        stage_cesa = CareerStage(
            active=True,
            name="Contrat CESA",
            cae_situation_id=situation_es.id,
            stage_type="contract",
        )
        stage_avct = CareerStage(
            active=True,
            name="Avenant contrat",
            cae_situation_id=None,
            stage_type="amendment",
        )
        stage_out = CareerStage(
            active=True,
            name="Sortie",
            cae_situation_id=situation_out.id,
            stage_type="exit",
        )
        session.add(stage_diag)
        session.add(stage_cape)
        session.add(stage_dpae)
        session.add(stage_cesa)
        session.add(stage_avct)
        session.add(stage_out)
        session.flush()
    return (situation_conv.id, situation_es.id, situation_out.id), (
        stage_diag.id,
        stage_cape.id,
        stage_dpae.id,
        stage_cesa.id,
        stage_avct.id,
        stage_out.id,
    )
def populate_default_datas():
    """
    Populate the database with missing default entries if needed
    """
    from autonomie.models.user.userdatas import CaeSituationOption
    from autonomie.models.career_stage import CareerStage
    from autonomie.models.career_path import TypeContratOption
    session = DBSESSION()
    # Populate contract types
    if session.query(TypeContratOption).filter(TypeContratOption.label=="CDD").count() == 0:
        session.add(TypeContratOption(label=u"CDD", order=0))
    if session.query(TypeContratOption).filter(TypeContratOption.label=="CDI").count() == 0:
        session.add(TypeContratOption(label=u"CDI", order=0))
    if session.query(TypeContratOption).filter(TypeContratOption.label=="CESA").count() == 0:
        session.add(TypeContratOption(label=u"CESA", order=0))
    session.flush()
    # Populate CAE situations
    situation_cand = session.query(CaeSituationOption).filter(CaeSituationOption.label=="Candidat").first()
    if situation_cand is None:
        situation_cand = CaeSituationOption(label=u"Candidat", order=0)
        session.add(situation_cand)
    situation_conv = session.query(CaeSituationOption).filter(CaeSituationOption.label=="En convention").first()
    if situation_conv is None:
        situation_conv = CaeSituationOption(label=u"En convention", is_integration=True)
        session.add(situation_conv)
    situation_es = session.query(CaeSituationOption).filter(CaeSituationOption.label=="Entrepreneur salarié").first()
    if situation_es is None:
        situation_es = CaeSituationOption(label=u"Entrepreneur salarié", is_integration=True)
        session.add(situation_es)
    situation_out = session.query(CaeSituationOption).filter(CaeSituationOption.label=="Sortie").first()
    if situation_out is None:
        situation_out = CaeSituationOption(label=u"Sortie")
        session.add(situation_out)
    session.flush()
    # Populate Career Stages
    if CareerStage.query().count() == 0:
        stage_diag = CareerStage(active=True,
                    name="Diagnostic",
                    cae_situation_id=None,
                    stage_type=None,
                )
        stage_cape = CareerStage(active=True,
                    name="Contrat CAPE",
                    cae_situation_id=situation_conv.id,
                    stage_type="entry",
                )
        stage_dpae = CareerStage(active=True,
                    name="Contrat DPAE",
                    cae_situation_id=None,
                    stage_type=None,
                )
        stage_cesa = CareerStage(active=True,
                    name="Contrat CESA",
                    cae_situation_id=situation_es.id,
                    stage_type="contract",
                )
        stage_avct = CareerStage(active=True,
                    name="Avenant contrat",
                    cae_situation_id=None,
                    stage_type="amendment",
                )
        stage_out = CareerStage(active=True,
                    name="Sortie",
                    cae_situation_id=situation_out.id,
                    stage_type="exit",
                )
        session.add(stage_diag)
        session.add(stage_cape)
        session.add(stage_dpae)
        session.add(stage_cesa)
        session.add(stage_avct)
        session.add(stage_out)
        session.flush()
    return (
        situation_conv.id,
        situation_es.id,
        situation_out.id
    ), (
        stage_diag.id,
        stage_cape.id,
        stage_dpae.id,
        stage_cesa.id,
        stage_avct.id,
        stage_out.id,
    )
Beispiel #7
0
 def load_items(self):
     return CareerStage.query(include_inactive=True).all()