本文整理汇总了Python中models.user.User.get_instance_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_instance_by_id方法的具体用法?Python User.get_instance_by_id怎么用?Python User.get_instance_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.get_instance_by_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_instance_by_id [as 别名]
def get(self):
"""
@apiDescription 用户登出
@api {get} /logout/? 登出
@apiGroup login
@apiError UserNotLogin 用户未登录
@apiError UserNotExists 用户不存在
"""
_uid = self.get_current_user()
if not _uid:
self.write(dict(
status=1,
msg="user does not logined",
))
return
user = User.get_instance_by_id(self.orm_session, _uid)
if not user:
self.write(dict(
status=1,
msg="user does not exist",
))
return
self.redis_session.delete(self.sid)
self.clear_cookie("sid")
self.write({})
示例2: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_instance_by_id [as 别名]
def get(self, uid):
"""
@apiDescription 获取用户信息
@api {get} /user/([0-9]+)/? 获取用户信息
@api {get} /shop/([0-9]+)/? 获取商家信息
@apiGroup user
@apiGroup shop
@apiParam {Number} uid 用户uid
@apiPermission user
@apiSuccess {Number} uid 用户uid
@apiSuccess {String} avatar 头像
@apiSuccess {String} name 用户名
@apiSuccess {Number} speed 配送时间,仅商家时出现
@apiSuccess {Number} sales_count 销量,仅商家出现
@apiSuccess {Number} lowest_money 起送价,仅商家出现
@apiSuccess {Boolean} invoice 是否开具发票,仅商家出现
@apiSuccess {Boolean} free_send 是否免费配送,如果非免费配送,统一收配送费1元
@apiSuccess {Integer} distance 距离,仅商家出现
@apiSuccess {Boolean} new_seller 是否为新商家,仅商家出现
@apiSuccess {Number} level 用户级别,仅获取自己信息时出现
@apiSuccess {String} register_at 注册时间,仅获取自己信息时出现
@apiSuccess {String} phone 手机号,仅获取自己信息时出现
@apiSuccess {Array} address 配送地址,仅获取自己信息时出现
@apiSuccessExample {json} Success Response:
{
"uid": 1,
"avatar": "http://xxxx.com/avatar.png",
"name": "001",
// 以下为用户获取自己信息时才会出现
"level": 0,
"register_at": "2016-03-27 00:00:00",
"phone": "99999",
"address": []
}
@apiError UserNotExists 用户不存在
"""
uid = int(uid)
# hack: 因为改url涉及面太广,所以通过查看self.require_shop 来判定吧-。-
shop = self.is_shop()
user = User.get_instance_by_id(self.orm_session, uid)
if user:
result = self._get_user_info(user, shop)
self.write(result)
else:
self.write(dict(
status=1,
msg="no such user",
))
示例3: wrapper
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_instance_by_id [as 别名]
def wrapper(obj, uid):
uid = int(uid)
user = User.get_instance_by_id(obj.orm_session, uid)
obj.seller = user
if user.level == level:
return func(obj, uid)
else:
obj.write(dict(
status=1,
msg="user level error",
))
return
示例4: put
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_instance_by_id [as 别名]
def put(self, uid):
"""
@apiDescription 修改用户信息
@api {put} /user/([0-9]+)/? 修改用户信息
@api {put} /shop/([0-9]+)/? 修改商家信息
@apiGroup user
@apiGroup shop
@apiParam {Number} [uid] uid
@apiParam {Number} [level] 级别
@apiParam {String} [passwd] 密码
@apiParam {String} [phone] 手机号
@apiParam {String} [name] 名字
@apiParam {String} [address] 地址
@apiPermission user
@apiError UserNotExists 用户不存在
"""
to_change = dict(
avatar=self.get_argument("avatar", None),
level=int(self.get_argument("level", 0)),
passwd=self.get_argument("passwd", None),
phone=self.get_argument("phone", None),
name=self.get_argument("name", None),
address=self.get_argument("addresses", None)
)
user = User.get_instance_by_id(self.orm_session, uid)
if not user:
self.write(dict(
status=1,
msg="user does not exists"
))
return
for key, value in to_change.items():
if value:
setattr(user, key, value)
self.orm_session.commit()
self.write({})
示例5: delete
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_instance_by_id [as 别名]
def delete(self, uid):
"""
@apiDescription 删除食品
@api {delete} /shop/([0-9]+)/foods/? 删除
@apiGroup food
@apiParam {Number} fid 食品id
@apiPermission seller
"""
uid = int(uid)
user = User.get_instance_by_id(self.orm_session, uid)
fid = int(self.get_argument("fid"))
if not user:
self.write(dict(
status=1,
msg="user not exist",
))
return
Food.delete(self.orm_session, user.id, fid)
self.write({})