Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 3
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))
Ejemplo n.º 4
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
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def query(self):
     return UserDatas.query()
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def query(self):
     return UserDatas.query()