def userdata(dbsession, cae_situation_option): from autonomie.models.user.userdatas 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
def userdatas(dbsession, user, cae_situation_option): from autonomie.models.user.userdatas import ( UserDatas, CompanyDatas, ) result = UserDatas(situation_situation=cae_situation_option, coordonnees_lastname="Userdatas", coordonnees_firstname="userdatas", coordonnees_email1="*****@*****.**", activity_companydatas=[ CompanyDatas( title='test entreprise', name='test entreprise', ) ], user_id=user.id) result.situation_situation_id = cae_situation_option.id dbsession.add(result) dbsession.flush() user.userdatas = result return result
def userdatas(dbsession, user, cae_situation_option): from autonomie.models.user.userdatas import ( UserDatas, CompanyDatas, ) result = UserDatas( situation_situation=cae_situation_option, coordonnees_lastname="Userdatas", coordonnees_firstname="userdatas", coordonnees_email1="*****@*****.**", activity_companydatas=[ CompanyDatas( title='test entreprise', name='test entreprise', ) ], user_id=user.id ) result.situation_situation_id = cae_situation_option.id dbsession.add(result) dbsession.flush() user.userdatas = result return result
def update_user_situation_cae(mapper, connection, target): """ Update - if needed - the CAE situation of the user when it's career path change """ if target.cae_situation_id is not None: from autonomie.models.user.userdatas import UserDatas user = UserDatas.query().filter( UserDatas.id == target.userdatas_id).first() situation = user.get_cae_situation_from_career_path(None) if user.situation_situation_id != situation.id: logger.debug(u"Update CAE situation of the user %s to '%s'" % (target.userdatas_id, situation.label)) connection.execute( "UPDATE user_datas SET situation_situation_id=%s WHERE id=%s" % (situation.id, user.id))
def test_userdatas_add_view(config, user, get_csrf_request_with_db): from autonomie.views.userdatas.userdatas import userdatas_add_view from autonomie.models.user.userdatas import UserDatas config.add_route('/users/{id}/userdatas/edit', '/users/{id}/userdatas/edit') req = get_csrf_request_with_db() req.context = user result = userdatas_add_view(user, req) assert result.code == 302 assert result.location == "/users/{0}/userdatas/edit".format(user.id) userdatas = UserDatas.query().filter_by(user_id=user.id).one() assert userdatas.coordonnees_civilite == user.civilite assert userdatas.coordonnees_lastname == user.lastname assert userdatas.coordonnees_firstname == user.firstname assert userdatas.coordonnees_email1 == user.email
def test_success(self, config, user, userdatas, get_csrf_request_with_db): from autonomie.views.userdatas.userdatas import UserDatasDeleteView from autonomie.models.user.userdatas import UserDatas config.add_route('/users/{id}', '/users/{id}') req = get_csrf_request_with_db() req.context = userdatas udatas_id = userdatas.id view = UserDatasDeleteView(req) res = view.__call__() req.dbsession.flush() assert res.code == 302 assert res.location == "/users/%s" % user.id assert UserDatas.get(udatas_id) is None
def userdatas_add_view(context, request): """ Add userdatas to an existing User object :param obj context: The pyramid context (User instance) :param obj request: The pyramid request """ logger.debug(u"Adding userdatas for the user %s" % context.id) user_datas = UserDatas() user_datas.user_id = context.id user_datas.coordonnees_civilite = context.civilite user_datas.coordonnees_lastname = context.lastname user_datas.coordonnees_firstname = context.firstname user_datas.coordonnees_email1 = context.email user_datas.situation_situation_id = get_default_cae_situation() request.dbsession.add(user_datas) request.dbsession.flush() return HTTPFound( request.route_path( USER_USERDATAS_EDIT_URL, id=context.id, ))
def userdatas_add_view(context, request): """ Add userdatas to an existing User object :param obj context: The pyramid context (User instance) :param obj request: The pyramid request """ logger.debug(u"Adding userdatas for the user %s" % context.id) user_datas = UserDatas() user_datas.user_id = context.id user_datas.coordonnees_civilite = context.civilite user_datas.coordonnees_lastname = context.lastname user_datas.coordonnees_firstname = context.firstname user_datas.coordonnees_email1 = context.email user_datas.situation_situation_id = get_default_cae_situation() request.dbsession.add(user_datas) request.dbsession.flush() return HTTPFound( request.route_path( USER_USERDATAS_EDIT_URL, id=context.id, ) )
def query(self): return UserDatas.query()