Exemple #1
0
def upgrade():
    import logging
    logger = logging.getLogger('alembic.here')
    op.add_column(
        "user_datas",
        sa.Column(
            'statut_social_status_today_id',
            sa.Integer,
            sa.ForeignKey('social_status_option.id'),
        ))
    op.add_column(
        "user_datas",
        sa.Column(
            "parcours_employee_quality_id",
            sa.Integer,
            sa.ForeignKey('employee_quality_option.id'),
        ))
    op.add_column(
        "user_datas",
        sa.Column("situation_antenne_id", sa.Integer,
                  sa.ForeignKey('antenne_option.id')))
    op.add_column("task", sa.Column(
        "internal_number",
        sa.String(40),
    ))
    op.add_column("task", sa.Column("company_index", sa.Integer))
    op.execute("alter table task CHANGE sequence_number project_index int(11)")
    op.add_column(
        "task",
        sa.Column(
            "company_id",
            sa.Integer,
            sa.ForeignKey('company.id'),
        ))
    from autonomie.models.base import (
        DBSESSION, )
    session = DBSESSION()

    add_company_id(session, logger)
    add_company_index(session, logger)
    add_internal_number(session, logger)

    logger.warn("Adding Contract Histories")
    from autonomie.models.user import UserDatas, ContractHistory
    for id_, last_avenant in UserDatas.query('id', 'parcours_last_avenant'):
        if last_avenant:
            session.add(
                ContractHistory(userdatas_id=id_, date=last_avenant,
                                number=-1))

    op.add_column("date_convention_cape_datas",
                  sa.Column('end_date', sa.Date(), nullable=True))
    op.execute("alter table customer MODIFY code VARCHAR(4);")
    op.execute("alter table project MODIFY code VARCHAR(4);")

    create_custom_treasury_modules(session, logger)

    from zope.sqlalchemy import mark_changed
    mark_changed(session)
Exemple #2
0
    def submit_success(self, appstruct):
        if self.context.__name__ == 'userdatas':
            model = self.schema.objectify(appstruct, self.context)
        else:
            from autonomie.views import render_api
            confirmation = self.request.GET.get('confirmation', '0')
            lastname = appstruct['coordonnees_lastname']
            email = appstruct['coordonnees_email1']
            if lastname and confirmation == '0':
                query = UserDatas.query().filter(
                    or_(
                        UserDatas.coordonnees_lastname == lastname,
                        UserDatas.coordonnees_email1 == email,
                    ))
                query_count = query.count()
                if query_count > 0:
                    if query_count == 1:
                        msg = u"Une entrée de gestion sociale similaire \
a déjà été créée: <ul>"

                    else:
                        msg = u"{0} entrées de gestion sociale similaires ont \
déjà été créées : <ul>".format(query_count)

                    for entry in query:
                        msg += u"<li><a href='%s'>%s (%s)</a></li>" % (
                            self.request.route_path('userdata', id=entry.id),
                            render_api.format_account(entry),
                            entry.coordonnees_email1,
                        )
                    msg += u"</ul>"
                    form = self._get_form()
                    form.action = self.request.current_route_path(
                        _query={
                            'action': 'new',
                            'confirmation': '1'
                        })
                    form.set_appstruct(appstruct)
                    datas = dict(
                        form=form.render(),
                        confirmation_message=msg,
                        confirm_form_id=form.formid,
                    )
                    datas.update(self._more_template_vars())
                    return datas

            model = self.schema.objectify(appstruct)

        model = self.dbsession.merge(model)
        self.dbsession.flush()

        self.post_integration(model)

        self.session.flash(self.validation_msg)
        return HTTPFound(self.request.route_path('userdata', id=model.id))
def userdata(dbsession):
    from autonomie.models.user import (UserDatas, CaeSituationOption,)
    u = UserDatas(
        situation_situation=CaeSituationOption.query().first(),
        coordonnees_firstname="firstname",
        coordonnees_lastname="lastname",
        coordonnees_email1="*****@*****.**",
    )
    dbsession.add(u)
    dbsession.flush()
    return u
Exemple #4
0
def userdata(dbsession, cae_situation_option):
    from autonomie.models.user import UserDatas
    u = UserDatas(
        situation_situation_id=cae_situation_option.id,
        coordonnees_firstname="firstname",
        coordonnees_lastname="lastname",
        coordonnees_email1="*****@*****.**",
    )
    dbsession.add(u)
    dbsession.flush()
    return u
Exemple #5
0
    def submit_success(self, appstruct):
        if self.context.__name__ == 'userdatas':
            model = self.schema.objectify(appstruct, self.context)
        else:
            from autonomie.views import render_api
            confirmation = self.request.GET.get('confirmation', '0')
            lastname = appstruct['coordonnees_lastname']
            email = appstruct['coordonnees_email1']
            if lastname and confirmation == '0':
                query = UserDatas.query().filter(
                    or_(
                        UserDatas.coordonnees_lastname == lastname,
                        UserDatas.coordonnees_email1 == email,
                    )
                )
                query_count = query.count()
                if query_count > 0:
                    if query_count == 1:
                        msg = u"Une entrée de gestion sociale similaire \
a déjà été créée: <ul>"
                    else:
                        msg = u"{0} entrées de gestion sociale similaires ont \
déjà été créées : <ul>".format(query_count)

                    for entry in query:
                        msg += u"<li><a href='%s'>%s (%s)</a></li>" % (
                            self.request.route_path('userdata', id=entry.id),
                            render_api.format_account(entry),
                            entry.coordonnees_email1,
                        )
                    msg += u"</ul>"
                    form = self._get_form()
                    form.action = self.request.current_route_path(
                        _query={'action': 'new', 'confirmation': '1'}
                    )
                    form.set_appstruct(appstruct)
                    datas = dict(
                        form=form.render(),
                        confirmation_message=msg,
                        confirm_form_id=form.formid,
                    )
                    datas.update(self._more_template_vars())
                    return datas

            model = self.schema.objectify(appstruct)

        model = self.dbsession.merge(model)
        self.dbsession.flush()

        self.post_integration(model)

        self.session.flash(self.validation_msg)
        return HTTPFound(self.request.route_path('userdata', id=model.id))
def get_userdatas():
    option = CaeSituationOption(label="Integre", is_integration=True)
    return UserDatas(
        situation_situation=option,
        coordonnees_lastname="test",
        coordonnees_firstname="test",
        coordonnees_email1="*****@*****.**",
        activity_companydatas=[CompanyDatas(
            title='test entreprise',
            name='test entreprise',
        )]
    )
Exemple #7
0
    def query_homonym(self, lastname, email):
        """
        collect the accounts with same name or email

        :param str lastname: The lastname to check
        :param str email: the email to check
        :returns: The SQLAlchemy query object
        :rtype: obj
        """
        query = UserDatas.query().filter(
            or_(
                UserDatas.coordonnees_lastname == lastname,
                UserDatas.coordonnees_email1 == email,
            ))
        return query
Exemple #8
0
def _export_user_datas(args, env):
    """
    Export userdatas as csv format

    Streams the output in stdout

    autonomie-export app.ini userdatas \
    --fields=coordonnees_address,coordonnees_zipcode,coordonnees_city,\
        coordonnees_sex,coordonnees_birthday,statut_social_status,\
        coordonnees_study_level,parcours_date_info_coll,parcours_prescripteur,\
        parcours_convention_cape,activity_typologie,sortie_date,sortie_motif \
    --where='[{"key":"created_at","method":"dr","type":"date",\
        "search1":"1999-01-01","search2":"2016-12-31"}]'\
    > /tmp/toto.csv

    :param dict args: The arguments coming from the command line
    :param dict env: The environment bootstraped when setting up the pyramid app
    """
    from autonomie.models.user import UserDatas

    logger = logging.getLogger(__name__)
    fields = get_value(args, "fields", "").split(',')
    where_str = get_value(args, "where", "{}")
    try:
        where = json.loads(where_str)
        if isinstance(where, dict):
            where = [where]
    except:
        logger.exception("Where should be in json format")
        where = []

    logger.debug("Fields : {0}".format(fields))
    logger.debug("Where : {0}".format(where))

    if where:
        query = _get_query(UserDatas, where)
    else:
        query = UserDatas.query()

    _stream_csv_rows(UserDatas, query, fields)
Exemple #9
0
 def query(self):
     return UserDatas.query()
Exemple #10
0
def upgrade():
    import logging
    logger = logging.getLogger('alembic.here')
    op.add_column(
        "user_datas",
        sa.Column(
            'statut_social_status_today_id',
            sa.Integer,
            sa.ForeignKey('social_status_option.id'),
        )
    )
    op.add_column(
        "user_datas",
        sa.Column(
            "parcours_employee_quality_id",
            sa.Integer,
            sa.ForeignKey('employee_quality_option.id'),
        )
    )
    op.add_column(
        "user_datas",
        sa.Column(
            "situation_antenne_id",
            sa.Integer,
            sa.ForeignKey('antenne_option.id')
        )
    )
    op.add_column(
        "task",
        sa.Column(
            "internal_number",
            sa.String(40),
        )
    )
    op.add_column(
        "task",
        sa.Column("company_index", sa.Integer)
    )
    op.execute("alter table task CHANGE sequence_number project_index int(11)")
    op.add_column(
        "task",
        sa.Column(
            "company_id",
            sa.Integer,
            sa.ForeignKey('company.id'),
        )
    )
    from autonomie.models.base import (
        DBSESSION,
    )
    session = DBSESSION()

    add_company_id(session, logger)
    add_company_index(session, logger)
    add_internal_number(session, logger)

    logger.warn("Adding Contract Histories")
    from autonomie.models.user import UserDatas, ContractHistory
    for id_, last_avenant in UserDatas.query('id', 'parcours_last_avenant'):
        if last_avenant:
            session.add(
                ContractHistory(
                    userdatas_id=id_,
                    date=last_avenant,
                    number=-1
                )
            )

    op.add_column(
        "date_convention_cape_datas",
        sa.Column('end_date', sa.Date(), nullable=True)
    )
    op.execute("alter table customer MODIFY code VARCHAR(4);")
    op.execute("alter table project MODIFY code VARCHAR(4);")

    create_custom_treasury_modules(session, logger)

    from zope.sqlalchemy import mark_changed
    mark_changed(session)
Exemple #11
0
 def query(self):
     return UserDatas.query()