本文整理汇总了Python中app.users.models.User.get方法的典型用法代码示例。如果您正苦于以下问题:Python User.get方法的具体用法?Python User.get怎么用?Python User.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import get [as 别名]
def get(self, id=None):
if id:
try:
user = User.get(id=id)
except User.DoesNotExist:
return Response(status=404)
else:
return Response(json.dumps(user.serialize), mimetype='application/json')
else:
return Response(status=404)
示例2: post
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import get [as 别名]
def post(self, id=None):
if id:
try:
User.get(id=id)
#hier prüfen ob der user den freund schon besitzt oder via app mit /<id>/friends/ ?
except User.DoesNotExist:
return Response(status=404)
else:
#add new user friend
resp = request.get_json()
friend = resp.get('friend')
accepted = resp.get('accepted') or False
blocked = resp.get('blocked') or False
friend = UserFriend.create(
user=id,
friend=friend,
accepted=accepted,
blocked=blocked,
)
return Response(json.dumps(friend.serialize), mimetype='application/json')
else:
return Response(status=404)
示例3: delete
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import get [as 别名]
def delete(self, id=None):
resp = request.get_json()
if id:
try:
user = User.get(id=id)
except User.DoesNotExist:
return Response(status=404)
else:
user.activated = resp.get('activated', user.activated)
user.save()
return Response(json.dumps(user.serialize), mimetype='application/json')
else:
return Response(status=404)
示例4: put
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import get [as 别名]
def put(self, id=None):
resp = request.get_json()
if id:
try:
user = User.get(id=id)
except User.DoesNotExist:
return Response(status=404)
else:
user.avatar = resp.get('avatar', user.avatar)
user.email = resp.get('email', user.email)
user.username = resp.get('username', user.username)
user.first_name = resp.get('first_name', user.first_name)
user.last_name = resp.get('last_name', user.last_name)
user.password = resp.get('password', user.password)
user.gender = resp.get('gender', user.gender)
user.save()
return Response(json.dumps(user.serialize), mimetype='application/json')
else:
return Response(status=404)
示例5: test_user_get_function
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import get [as 别名]
def test_user_get_function(self):
test_list = [
dict(username='flatcoke', password='qwer1235',
email='[email protected]', name='TaeminKim', ),
dict(username='c121213', password='12341234',
email='[email protected]', name='Kevin', ),
dict(username='gogogohaha', password='asdfasdf',
email='[email protected]', name='TaeMin', ),
dict(username='taemin-kim', password='googoo',
email='[email protected]', name='Noah', ),
dict(username='11good', password='1',
email='[email protected]', name='flatcoke', ),
]
for i in test_list:
user = User(i['username'], i['name'], i['email'], i['password'])
db.session.add(user)
db.session.commit()
result = User.get(user.id)
self.assertIsInstance(result, User)
self.assertEqual(result.username, i['username'])
self.assertEqual(result.name, i['name'])
self.assertNotEqual(result.password, i['password'])