Esempio n. 1
0
def cae_situation_option(dbsession):
    from autonomie.models.user.userdatas import (
        CaeSituationOption, )
    option = CaeSituationOption(
        is_integration=False,
        label=u"CaeSituationOption",
    )
    dbsession.add(option)
    dbsession.flush()
    return option
Esempio n. 2
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()
Esempio n. 3
0
 def get_cae_situation_from_career_path(self, date):
     """
     Return the CaeSituation of the current user
     at the given date computed from the career path
     """
     from autonomie.models.career_path import CareerPath
     from autonomie.models.user.userdatas import CaeSituationOption
     if date is None:
         date=datetime.date.today()
     last_situation_path = CareerPath.query(self.id).filter(
         CareerPath.start_date <= date
     ).filter(
         CareerPath.cae_situation_id != None
     ).first()
     situation = CaeSituationOption.query().filter(
         CaeSituationOption.id == last_situation_path.cae_situation_id
     ).first()
     return situation
Esempio n. 4
0
 def get_cae_situation_from_career_path(self, date):
     """
     Return the CaeSituation of the current user
     at the given date computed from the career path
     """
     from autonomie.models.career_path import CareerPath
     from autonomie.models.user.userdatas import CaeSituationOption
     if date is None:
         date = datetime.date.today()
     last_situation_path = CareerPath.query(self.id).filter(
         CareerPath.start_date <= date
     ).filter(
         CareerPath.cae_situation_id != None
     ).first()
     if last_situation_path is None:
         return None
     else:
         situation = CaeSituationOption.query().filter(
             CaeSituationOption.id == last_situation_path.cae_situation_id
         ).first()
         return situation
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,
    )
Esempio n. 6
0
def deferred_situation_id_validator(node, kw):
    return colander.OneOf(
        [option.id for option in CaeSituationOption.query()]
    )
Esempio n. 7
0
def deferred_situation_select(node, kw):
    values = [('', u"Sélectionner un statut")]
    options = CaeSituationOption.query()
    for option in options:
        values.append((option.id, option.label))
    return deform.widget.SelectWidget(values=values)