本文整理汇总了Python中helpers.queryhelper.QueryHelper.get_singles_by_cid方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHelper.get_singles_by_cid方法的具体用法?Python QueryHelper.get_singles_by_cid怎么用?Python QueryHelper.get_singles_by_cid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.queryhelper.QueryHelper
的用法示例。
在下文中一共展示了QueryHelper.get_singles_by_cid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_singles_by_cid [as 别名]
def post(self):
"""Create a new corp single.
"""
try:
data = DotDict(json_decode(self.request.body))
logging.info("[UWEB] Add single request: %s, cid: %s", data, self.current_user.cid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. Exception: %s", e.args)
self.write_ret(status)
return
try:
singles = QueryHelper.get_singles_by_cid(self.current_user.cid, self.db)
if len(singles) > LIMIT.REGION - 1:
self.write_ret(ErrorCode.REGION_ADDITION_EXCESS)
return
status = ErrorCode.SUCCESS
single_id = -1 # default value
single_name = data.single_name
single_shape = int(data.single_shape)
if single_shape == UWEB.REGION_SHAPE.CIRCLE:
circle = DotDict(data.circle)
longitude = circle.longitude
latitude = circle.latitude
radius = circle.radius
single_info = dict(
single_name=single_name,
longitude=longitude,
latitude=latitude,
radius=radius,
shape=single_shape,
cid=self.current_user.cid,
)
single_id = add_single(single_info, self.db, self.redis)
elif single_shape == UWEB.REGION_SHAPE.POLYGON:
polygon = data.polygon
points_lst = []
points = ""
for p in polygon:
tmp = ",".join([str(p["latitude"]), str(p["longitude"])])
points += tmp
points_lst.append(tmp)
points = ":".join(points_lst)
single_info = dict(
single_name=single_name, points=points, shape=single_shape, cid=self.current_user.cid
)
single_id = add_single(single_info, self.db, self.redis)
else:
logging.error(
"[UWEB] Add single failed, unknown single_shape: %s, uid: %s", single_shape, self.current_user.uid
)
self.write_ret(status, dict_=DotDict(single_id=single_id))
except Exception as e:
logging.exception("[UWEB] cid: %s create single failed. Exception: %s", self.current_user.cid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例2: get
# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_singles_by_cid [as 别名]
def get(self):
""" Get singles by cid"""
status = ErrorCode.SUCCESS
try:
cid = self.current_user.cid
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception(
"[UWEB] uid: %s get region data format illegal. Exception: %s", self.current_user.uid, e.args
)
self.write_ret(status)
return
try:
res = []
singles = QueryHelper.get_singles_by_cid(self.current_user.cid, self.db)
for single in singles:
if single.single_shape == UWEB.REGION_SHAPE.CIRCLE:
r = DotDict(
single_id=single.single_id,
single_name=single.single_name,
single_shape=single.single_shape,
circle=DotDict(latitude=single.latitude, longitude=single.longitude, radius=single.radius),
)
elif single.single_shape == UWEB.REGION_SHAPE.POLYGON:
polygon = []
points = single.points
point_lst = points.split(":")
for point in point_lst:
latlon = point.split(",")
dct = {"latitude": latlon[0], "longitude": latlon[1]}
polygon.append(dct)
r = DotDict(
single_id=single.single_id,
single_name=single.single_name,
single_shape=single.single_shape,
polygon=polygon,
)
res.append(r)
self.write_ret(status, dict_=DotDict(res=res))
except Exception as e:
logging.exception("[UWEB] cid: %s get singles failed. Exception: %s", cid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)