本文整理汇总了Python中models.user.UserModel.get_user_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python UserModel.get_user_by_id方法的具体用法?Python UserModel.get_user_by_id怎么用?Python UserModel.get_user_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.UserModel
的用法示例。
在下文中一共展示了UserModel.get_user_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import get_user_by_id [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