當前位置: 首頁>>代碼示例>>Python>>正文


Python UserModel.get_user_by_username方法代碼示例

本文整理匯總了Python中models.user.UserModel.get_user_by_username方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.get_user_by_username方法的具體用法?Python UserModel.get_user_by_username怎麽用?Python UserModel.get_user_by_username使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.user.UserModel的用法示例。


在下文中一共展示了UserModel.get_user_by_username方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: put

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import get_user_by_username [as 別名]
    def put(self, user_id):
        data = json_decode(self.request.body)

        if not self.valid_new_user(data['username'], data['password'], data['nickname'], data['department'], data['permission']):
            self.finish_json(errcode=400, errmsg='wrong argument')
            return
        else:
            user = UserModel.get_user_by_id(self.db, user_id)
            if user is None:
                self.finish_json(errcode=404, errmsg="user id not exist")
                return
            else:

                tmp_user = UserModel.get_user_by_username(
                    self.db, data['username'])
                if tmp_user and (tmp_user.id != int(user_id)):
                    print 'exist username'
                    self.finish_json(errcode=409, errmsg="username exist")
                    return

                try:
                    UserModel.update_by_id(self.db, user_id, data['username'], data[
                                           'password'], data['nickname'], data['department'], data['permission'])
                    self.finish_json()
                    return
                except Exception, e:
                    print e
                    self.finish_json(errcode=507, errmsg=str(e))
                    return
開發者ID:icyCloud,項目名稱:test_p_o_i,代碼行數:31,代碼來源:user.py

示例2: post

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import get_user_by_username [as 別名]
    def post(self):
        user = ObjectDict(json_decode(self.request.body))
        print user

        if not self.valid_new_user(user.username, user.password, user.nickname, user.department, user.permission):
            self.finish_json(errcode=400, errmsg="invalid arguments")

        else:
            _user = UserModel.get_user_by_username(self.db, user.username)

            if _user is not None:

                print 'username has been used'
                self.finish_json(errcode=400, errmsg="exist username")
            else:

                try:
                    _user = UserModel.add_user(
                        self.db, user.username, user.password, user.nickname, user.department, user.permission)
                    self.finish_json(result=_user.tojson())
                except Exception, e:
                    print e
                    self.finish_json(errcode=507, errmsg=str(e))
開發者ID:icyCloud,項目名稱:test_p_o_i,代碼行數:25,代碼來源:user.py


注:本文中的models.user.UserModel.get_user_by_username方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。