当前位置: 首页>>代码示例>>Python>>正文


Python User.get_instance_by_id方法代码示例

本文整理汇总了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({})
开发者ID:jiajunhuang,项目名称:graduation,代码行数:30,代码来源:login.py

示例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",
            ))
开发者ID:jiajunhuang,项目名称:graduation,代码行数:55,代码来源:user.py

示例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
开发者ID:jiajunhuang,项目名称:graduation,代码行数:15,代码来源:check.py

示例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({})
开发者ID:jiajunhuang,项目名称:graduation,代码行数:43,代码来源:user.py

示例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({})
开发者ID:jiajunhuang,项目名称:graduation,代码行数:24,代码来源:food.py


注:本文中的models.user.User.get_instance_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。