本文整理汇总了Python中TrackerRestApi.Session.merge方法的典型用法代码示例。如果您正苦于以下问题:Python Session.merge方法的具体用法?Python Session.merge怎么用?Python Session.merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrackerRestApi.Session
的用法示例。
在下文中一共展示了Session.merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updatePlace
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [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
示例2: getCode
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [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
示例3: updateDGeo
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [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
示例4: updateGroup
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [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
示例5: logout
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [as 别名]
def logout():
s = Session()
u = current_user
u.authenticated = False
s.merge(u)
s.commit()
s.close()
logout_user()
return True
示例6: login
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [as 别名]
def login(id, code, platform, hw_id, reg_id):
if platform not in ["A", "a", "I", "i"]:
raise ServerError("Incorrect platform.")
s = Session()
u = s.query(TrUser).filter(TrUser.id == id).first()
if u is None:
s.close()
raise ServerError("User doesn't exist.")
#TODO:: expired date of code
exp = int((datetime.datetime.now() - u.last_modified).total_seconds())
print exp
if exp > app.config['SMS_CODE_LIFETIME']:
s.close()
raise ServerError("Invalid code.")
if u.auth_code == code:
u.authenticated = True
s.merge(u)
s.commit()
login_user(u)
"""Save token for push notification"""
pt = s.query(TrPushToken).filter(TrPushToken.platform == platform.upper()).\
filter(TrPushToken.hardware_id == hw_id).first()
if pt is None:
pt = TrPushToken(hw_id, platform.upper(), reg_id, id)
s.add(pt)
s.commit()
else:
setattr(pt, 'hardware_id', hw_id)
setattr(pt, 'token', reg_id)
setattr(pt, 'user_id', id)
s.merge(pt)
s.commit()
s.close()
return True
示例7: addHelp
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [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
示例8: getConfigTest
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import merge [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