本文整理汇总了Python中TrackerRestApi.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrackerRestApi.Session
的用法示例。
在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateDGeo
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例2: delFavFeed
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例3: updateGroup
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例4: unregDevice
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例5: getCode
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例6: delComment
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例7: addComment
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例8: updatePlace
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例9: addLocation
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例10: logout
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [as 别名]
def logout():
s = Session()
u = current_user
u.authenticated = False
s.merge(u)
s.commit()
s.close()
logout_user()
return True
示例11: addPlace
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例12: addGroup
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例13: delFollower
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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
示例14: unsubFeed
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [as 别名]
def unsubFeed(user_id, feed_id):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
u = session.query(TrUser).filter(TrUser.id == user_id).first()
if u is None:
session.close()
raise ServerError("User doesn't exist.")
for f in u.feeds:
if f.id == feed_id:
u.feeds.remove(f)
session.commit()
break
session.close()
return True
示例15: addHelp
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import commit [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