本文整理汇总了Python中TrackerRestApi.Session.close方法的典型用法代码示例。如果您正苦于以下问题:Python Session.close方法的具体用法?Python Session.close怎么用?Python Session.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrackerRestApi.Session
的用法示例。
在下文中一共展示了Session.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addLocation
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [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
示例2: addComment
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [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
示例3: delComment
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [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
示例4: getDGeos
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getDGeos(user_id, device_id):
session = Session()
dev = session.query(TrDevice).filter(TrDevice.device_userID == user_id).all()
if dev is None:
raise ServerError("Device doesn't exist.")
t = session.query(TrDevice.device_ID).filter(TrDevice.device_ID == device_id).\
filter(TrDevice.device_userID == user_id).subquery('t')
geos = session.query(TrDGeozone).filter(TrDGeozone.device_id == t.c.device_ID)
lst = []
for geo in geos:
ret = {
"id": geo.id,
"name": geo.name,
"shape": geo.shape,
"radius": geo.radius,
"center": geo.center,
"color": geo.color,
"state": bool(geo.state)}
lst.append(ret)
session.close()
return lst
示例5: getDLocation
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getDLocation(user_id, device_id, since):
session = Session()
if session.query(TrUser).get(user_id) is None:
raise ServerError("User does not exist")
lst = []
locs = session.query(TrDLocation).join(TrDevice, TrDLocation.device_id == TrDevice.device_ID).\
filter(TrDLocation.device_id == device_id).\
filter(TrDLocation.creation_time > datetime.datetime.fromtimestamp(since)).\
filter(TrDevice.device_userID == user_id).all()
for loc in locs:
lst.append({
"lat_log": loc.lat_log,
"creation_date": int(loc.creation_time.strftime("%s")),
"speed": loc.speed,
"sensors": {
"battery": 10,
"accel": True,
"temp": -19}
})
session.close()
return lst
示例6: getCode
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [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
示例7: getDealers
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getDealers(user_id, vehicle_id, location, radius):
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.")
lat_lon = location.split(',')
base_point = GeoLocation.from_degrees(float(lat_lon[0]), float(lat_lon[1]))
sw, ne = base_point.bounding_locations(radius)
print sw.deg_lat
print sw.deg_lon
print ne.deg_lat
print ne.deg_lon
ds = session.query(TrDealer).filter(TrDealer.maker == v.car_model.marka_name).\
filter(TrDealer.latitude > sw.deg_lat).filter(TrDealer.longitude > sw.deg_lon).\
filter(TrDealer.latitude < ne.deg_lat).filter(TrDealer.longitude < ne.deg_lon).all()
ret = [fillDealerResponse(d) for d in ds]
session.close()
return ret
示例8: upload
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def upload(target):
session = Session()
tbl = {'profile': (TrUser, app.config.get('PROFILES_IMG_PATH')),
'vehicle': (TrVehicle, app.config.get('VEHICLES_IMG_PATH')),
'group': (TrGroup, app.config.get('GROUPS_IMG_PATH'))}
if tbl.get(target) is None:
session.close()
return ("Error: Incorrect target.")
obj = session.query(tbl[target][0]).get(int(request.headers.get('id')))
if obj is None:
session.close()
return ("Error: Object doesn't exist.")
path = tbl[target][1]
file = request.files['file']
app.logger.debug('Object id: %d' % int(request.headers.get('id')))
app.logger.debug('Filename: %s' % file.filename)
if file and allowed_file(file.filename):
if obj.pic is not None:
app.logger.debug('Field pic is not empty.')
try:
app.logger.debug('Trying to delete old file.')
os.remove(path + obj.pic)
except:
pass
engine.execute(" \
UPDATE " + obj.__tablename__ + " SET pic=concat( \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed:=round(rand(" + str(obj.id) + ")*4294967296))*62+1, 1), \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed:=round(rand(@seed)*4294967296))*62+1, 1), \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed:=round(rand(@seed)*4294967296))*62+1, 1), \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed:=round(rand(@seed)*4294967296))*62+1, 1), \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed:=round(rand(@seed)*4294967296))*62+1, 1), \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed:=round(rand(@seed)*4294967296))*62+1, 1), \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed:=round(rand(@seed)*4294967296))*62+1, 1), \
substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', rand(@seed)*62+1, 1), \
'.jpg' \
) \
WHERE id="+ str(obj.id) + "; \
")
session.close()
s = Session()
ob = session.query(tbl[target][0]).get(int(request.headers.get('id')))
file.save(os.path.join(path, ob.pic))
s.close()
return "Ok"
else:
session.close()
return "Error: incorrect file."
示例9: getFollowers
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getFollowers(user_id):
'''Test user_id: 998'''
session = Session()
if session.query(TrUser).get(user_id) is None:
raise ServerError("User does not exist")
followers = []
# SELECT *
# FROM tr_follower AS f
# LEFT JOIN b_user AS u ON u.ID = f.slave_id
# WHERE f.master_id = 998
t = session.query(TrFollower.slave_id).filter(TrFollower.master_id == user_id).subquery('t')
query = session.query(TrUser).filter(TrUser.ID == t.c.slave_id)
for user in query:
follower = next((x for x in user.masters if x.master_id == user_id), None)
if follower is None:
raise ServerError('Internal error')
followers.append({
"id": follower.id,
"alias": follower.alias if follower.alias is not None else user.LOGIN,
"type": auth_type(user),
"login": user.LOGIN,
"first_name": "" if user.NAME is None else user.NAME,
"last_name": "" if user.LAST_NAME is None else user.LAST_NAME})
session.close()
return followers
示例10: getFGeos
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getFGeos(user_id, follower_id):
session = Session()
if session.query(TrUser).get(user_id) is None:
raise ServerError("User does not exist")
follower = session.query(TrFollower).filter(TrFollower.id == follower_id).first()
if follower is None:
raise ServerError('Follower does not exist')
lst = []
for geo in follower.geos:
lst.append({
"id": geo.id,
"name": geo.name,
"state": geo.state,
"shape": geo.shape,
"center": geo.center,
"radius": geo.radius,
"color": geo.color
})
session.close()
return lst
示例11: logout
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def logout():
s = Session()
u = current_user
u.authenticated = False
s.merge(u)
s.commit()
s.close()
logout_user()
return True
示例12: getAccList
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getAccList(user_id, list):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
us = session.query(TrUser).filter(TrUser.login.in_(list.split(','))).all()
lst = [fillUser(u) for u in us]
session.close()
return lst
示例13: getPlaces
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getPlaces(user_id):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
pls = session.query(TrPlace).filter(TrPlace.user_id == uid).all()
lst = [fillPlaceResponse(p) for p in pls]
session.close()
return lst
示例14: getDevices
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getDevices(user_id):
session = Session()
uid = int(current_user.get_id()) if app.config.get('LOGIN_DISABLED') is False else user_id
t = session.query(TrVehicle.id).filter(TrVehicle.user_id == uid).subquery('t')
devs = session.query(TrDevice).filter(TrDevice.vehicle_id == t.c.id).all()
lst = [fillDeviceResponse(dev) for dev in devs]
session.close()
return lst
示例15: getAllDealers
# 需要导入模块: from TrackerRestApi import Session [as 别名]
# 或者: from TrackerRestApi.Session import close [as 别名]
def getAllDealers(user_id):
session = Session()
dls = session.query(TrDealer).all()
if dls is None:
session.close()
raise ServerError("Dealers were not found.")
ret = [fillDealerResponse(dl) for dl in dls]
session.close()
return ret