当前位置: 首页>>代码示例>>Python>>正文


Python Session.rollback方法代码示例

本文整理汇总了Python中TrackerRestApi.Session.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python Session.rollback方法的具体用法?Python Session.rollback怎么用?Python Session.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TrackerRestApi.Session的用法示例。


在下文中一共展示了Session.rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delComment

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def delComment(user_id, group_id, id):

    session = Session()

    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    t = session.query(association_table_user_group).filter(association_table_user_group.user_id == uid).\
                                                    filter(association_table_user_group.group_id == group_id).subquery('t')
    m = session.query(TrGroupComment).filter(TrGroupComment.user_group_id == t.c.id).\
                                        filter(TrGroupComment.id == id).first()

    if m is None:
        session.close()
        raise ServerError("Message doesn't exist.")

    try:
        session.delete(m)
        session.commit()
    except:
        session.rollback()
        raise ServerError("Can't delete message.")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:27,代码来源:group.py

示例2: addComment

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def addComment(user_id, group_id, message):

    session = Session()

    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    ug = session.query(association_table_user_group).filter(association_table_user_group.user_id == uid).\
                                                    filter(association_table_user_group.group_id == group_id).first()
    if ug is None:
        session.close()
        raise ServerError("Group doesn't exist.")

    gm = TrGroupComment(message, ug.id)

    try:
        session.add(gm)
        session.commit()
        session.refresh(gm)
    except:
        session.rollback()
        raise ServerError("Can't add message.")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:27,代码来源:group.py

示例3: updateDGeo

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def updateDGeo(user_id=null, id=null, **kwargs):

    session = Session()

    t = session.query(TrDevice.device_ID).filter(TrDevice.device_userID == user_id).subquery('t')
    geo = session.query(TrDGeozone).filter(TrDGeozone.device_id == t.c.device_ID).filter(TrDGeozone.id == id).first()

    if geo is None:
        session.close()
        raise ServerError("Geozone doesn't exist.")

    """check all params"""
    if not isAllIncluded(kwargs.keys(), geo_mandatory_params + geo_option_params):
        session.close()
        raise InvalidParamsError("Incorrect parameters.")

    # for k,v in kwargs.iteritems():
    #     if k not in geo_params:
    #         session.close()
    #         raise ServerError("Incorrect arg: %s" % k)

    for k,v in kwargs.iteritems():
        setattr(geo, k, v)

    try:
        session.merge(geo)
        session.commit()
    except:
        session.rollback()
        raise ServerError("Can't update")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:36,代码来源:geo.py

示例4: getCode

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def getCode(number):

    session = Session()

    sms = SmsEpochta()
    code = ''.join(random.choice(string.digits) for _ in range(app.config.get('SMS_CODE_LEN')))

    u = session.query(TrUser).filter(TrUser.login == number).first()

    if u is None:
        u = TrUser(login=number, auth_code=code, active='N')
        session.add(u)
    else:
        setattr(u, 'auth_code', code)
        setattr(u, 'active', 'N')
        session.merge(u)

    try:
        session.commit()
        session.refresh(u)
    except:
        session.rollback()
        raise ServerError("Can't generate new code.")
    finally:
        session.close()

    sms.send(number, code)

    return u.id
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:31,代码来源:auth.py

示例5: addLocation

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def addLocation(user_id, points):

    session = Session()

    if session.query(TrUser).get(user_id) is None:
        raise ServerError("User does not exist")

    if len(points) <= 0:
        raise ServerError("Points is empty.")

    location = []

    for point in points:
        location.append(TrULocation(lat_log=point['location'], accuracy=point['accuracy'],
                creation_time=datetime.datetime.fromtimestamp(int(point['timestamp'])).strftime('%Y-%m-%d %H:%M:%S'),
                battery=point['properties'].get('battery'),
                speed=point['properties'].get('speed'),
                user_id=user_id))

    try:
        session.add_all(location)
        session.commit()
    except:
        session.rollback()
        raise ServerError("Can't add new locations")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:31,代码来源:location.py

示例6: unregDevice

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def unregDevice(user_id, vehicle_id, device_id):

    session = Session()

    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    v = session.query(TrVehicle).filter(TrVehicle.user_id == uid).\
                                filter(TrVehicle.id == vehicle_id).first()

    if v is None:
        session.close()
        raise ServerError("Vehicle doesn't exist.")

    if v.device is None or v.device.id != device_id:
        session.close()
        raise ServerError("Incorrect device or doesn't exist.")

    try:
        v.device.stat = False
        v.device = None
        session.commit()
    except:
        session.rollback()
        raise ServerError("Can't unregister device.")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:30,代码来源:device.py

示例7: updateGroup

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def updateGroup(user_id, id, **kwargs):

    session = Session()

    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    g = session.query(TrGroup).filter(TrGroup.id == id).filter(TrGroup.user_id == uid).first()

    if g is None:
        session.close()
        raise ServerError("Group doesn't exist.")

    if not isAllIncluded(kwargs.keys(), group_mandatory_params + group_option_params):
        session.close()
        raise InvalidParamsError("Incorrect parameters.")

    for k,v in kwargs.iteritems():
        setattr(g, k, v)

    try:
        session.merge(g)
        session.commit()
    except:
        session.rollback()
        raise ServerError("Can't update group.")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:31,代码来源:group.py

示例8: updatePlace

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def updatePlace(user_id, place_id, **kwargs):

    session = Session()
    
    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    p = session.query(TrPlace).filter(TrPlace.user_id == uid).filter(TrPlace.id == place_id).first()

    if p is None:
        session.close()
        raise ServerError("Place doesn't exist.")

    """check all params"""
    if not isAllIncluded(kwargs.keys(), place_mandatory_params + place_option_params):
        session.close()
        raise InvalidParamsError("Incorrect parameters.")

    for k,v in kwargs.iteritems():
        setattr(p, k, v)

    try:
        session.merge(p)
        session.commit()
    except:
        session.rollback()
        raise ServerError("Can't update place.")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:32,代码来源:place.py

示例9: delFavFeed

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def delFavFeed(user_id, feed_id, id):

    session = Session()

    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    u_f = session.query(association_table_user_feed).filter_by(user_id=uid).filter_by(feed_id=feed_id).first()
    if u_f is None:
        session.close()
        raise ServerError("User or feed doesn't exist.")

    uf_fav = session.query(TrUserFeedFav).filter_by(uf_id=u_f.id).filter_by(feed_news_id=id).first()

    if uf_fav is not None:

        try:
            session.delete(uf_fav)
            session.commit()
        except:
            session.rollback()
            raise ServerError("Can't delete item from favorites.")
        finally:
            session.close()
    else:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:29,代码来源:feed.py

示例10: addPlace

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def addPlace(user_id, title, longitude, latitude, type, desc):

    session = Session()
    
    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    p = TrPlace(user_id=uid, title=title, longitude=float(longitude), latitude=float(latitude), type=type, desc=desc)

    try:
        session.add(p)
        session.commit()
        session.refresh(p)
    except:
        session.rollback()
        raise ServerError("Can't add place.")
    finally:
        session.close()

    return p.id
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:21,代码来源:place.py

示例11: addGroup

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def addGroup(user_id, title, desc, invitation, meeting, help):

    session = Session()

    uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id

    g = TrGroup(title=title, desc=desc, invitation=invitation, meeting=meeting, help=help, user_id=uid)

    try:
        session.add(g)
        session.commit()
        session.refresh(g)
    except:
        session.rollback()
        raise ServerError("Can't add group.")
    finally:
        session.close()

    return g.id
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:21,代码来源:group.py

示例12: delFollower

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def delFollower(user_id, follower_id):
    '''Delete follower by id'''

    session = Session()

    if session.query(TrUser).get(user_id) is None:
        raise ServerError("User does not exist")

    follower = session.query(TrFollower).filter_by(id=follower_id).first()

    try:
        session.delete(follower)
        session.commit()
    except:
        session.rollback()
        raise ServerError("Can't delete")
    finally:
        session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:22,代码来源:follower.py

示例13: getConfigTest

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def getConfigTest(hw_id):

    session = Session()

    followers = session.query(TrFollower).filter(TrFollower.master_id == 998).\
                                filter(TrFollower.slave_id > 963).\
                                filter(TrFollower.slave_id < 975).all()

    x = [int(f.slave_id) for f in followers if f.hw_id == hw_id]
    if len(x) == 1:
        user_id = x[0]
    elif len(x) == 0:
        folls = [f for f in followers if f.hw_id is None]
        if len(folls) == 0:
            # no available slots for testers
            raise ServerError("Can't add new tester. No available slots.")
        else:
            foll = folls[0]
            setattr(foll, 'hw_id', hw_id)
            try:
                session.merge(foll)
                session.commit()
                user_id = foll.slave_id
            except:
                session.rollback()
                raise ServerError("Can't update. Server is unavailable.")
            finally:
                session.close()
    else:
        raise ServerError("Double hw_id.")


    conf = {
                "user_id":                  user_id,
                "accuracy":                 200,
                "updates_on":               True,
                "server_update_sec":        300,
                "location_update_sec":      60
    }

    return conf
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:43,代码来源:config.py

示例14: addHelp

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def addHelp(user_id,vehicle_id,message,lat_log, phone):

    session = Session()

    v = session.query(TrVehicle).filter(TrVehicle.id == vehicle_id).filter(TrVehicle.user_id == user_id).first()

    if v is None:
        session.close()
        raise ServerError("Vehicle doesn't exist.")

    if v.help is None:
        """Add new message"""
        message = TrHelp(vehicle_id=v.id, message=message, lat_log=lat_log)

        try:
            session.add(message)
            session.commit()
        except:
            session.rollback()
            raise ServerError("Can't add help message.")
        finally:
            session.close()

    else:
        """Update existing message"""
        help = session.query(TrHelp).filter(TrHelp.vehicle_id == v.id).first()

        setattr(help, 'message', message)
        setattr(help, 'lat_log', lat_log)
        setattr(help, 'creation_date', func.now())

        try:
            session.merge(help)
            session.commit()
        except:
            session.rollback()
            raise ServerError("Can't update")
        finally:
            session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:43,代码来源:help.py

示例15: delHelp

# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import rollback [as 别名]
def delHelp(user_id,vehicle_id):

    session = Session()

    v = session.query(TrVehicle).filter(TrVehicle.id == vehicle_id).filter(TrVehicle.user_id == user_id).first()

    if v is None:
        session.close()
        raise ServerError("Device doesn't exist.")

    if v.help is not None:
        try:
            session.delete(v.help)
            session.commit()
        except:
            session.rollback()
            raise ServerError("Can't delete")
        finally:
            session.close()

    return True
开发者ID:toxxin,项目名称:TrackerRestApi,代码行数:23,代码来源:help.py


注:本文中的TrackerRestApi.Session.rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。