本文整理汇总了Python中database.User.find方法的典型用法代码示例。如果您正苦于以下问题:Python User.find方法的具体用法?Python User.find怎么用?Python User.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.User
的用法示例。
在下文中一共展示了User.find方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import find [as 别名]
def post(self):
player_id = self.get_argument("id", -1);
player = User.find(_id = player_id)
portrait = None
family = "-1"
position = "-1"
percentage = 0
if player.headPortrait_url is not None:
portrait = player.headPortrait_url
#if player.family is not None:
# family = player.family.name
# position= player.family_position.name
if player.total_games > 0:
percentage = (player.won_games * 1.0) / player.total_games
message = {
"status": "success",
"name": player.screen_name,
"head_portrait": portrait,
"family": family,
"position": position,
"level": player.level,
"asset": player.asset,
"percentage": "%.2f%%" % (percentage * 100),
"total_games": player.total_games,
"won_games": player.won_games,
"max_reward": player.max_reward,
"last_login": datetime.fromtimestamp(player.last_login).strftime("%Y-%m-%d %H:%M:%S"),
"signature": player.signature or "This guy is too lazy to leave a signature",
"friends": str(player.friends),
"gender": player.gender
}
self.write(json.dumps(message))
self.finish()
示例2: test_mongo_user
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import find [as 别名]
def test_mongo_user(self):
user = User.create(testuser,'facebook')
self.assertTrue( user )
self.assertIsInstance(user , User )
self.assertIn('str_name', user.info())
uid = user._id
usersame = User.find(uid)
self.assertEqual(usersame.info(), user.info())
self.assertIsInstance(user.info(), dict)
#edit
self.assertTrue( user.edit({'str_name':'BurgerKing'}) )
self.assertIn('BurgerKing', str(user.info()))
self.assertIn('facebook', str(user.info(['str_type'])))
# Remove does it return True? if so sucessful remove.
self.assertTrue( user.delete() )
self.assertFalse( user.is_alive)
self.assertFalse( user.info())
self.assertFalse(User.find(uid))
示例3: cmd_sit
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import find [as 别名]
def cmd_sit(self, args):
print "sit received"
source = args['source']
private_key = args['private_key']
stake = args['stake']
user = User.find(_id=args['user_id'])
print args['user_id']
current_room = self.room_list[args["room_id"]]
(status, msg) = current_room.sit(user, int(args["seat"]), source, private_key,stake)
if status:
message = {"status": "success" }
else:
message = {"status": "failed", "msg": msg}
self.channel.basic_publish( exchange = self.exchange,
routing_key = source,
body = json.dumps(message))
示例4: addBuddy
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import find [as 别名]
def addBuddy(self):
user = self.user
friend_id = self.get_argument("user_id")
print "new friend ",friend_id
friend_list = user.friends
for friend in friend_list:
print "old friend: ",friend
if friend_id == friend:
message = {"status": "friend already in the list"}
self.finish(json.dumps(message))
return
friend = User.find(_id = friend_id)
if friend == None:
message = {"status": "friend doesn't exist"}
self.finish(json.dumps(message))
return
friend_list.append(friend.id)
user.friends = friend_list # Just for saving the result
message = {"status": "friend added"}
print user.friends
self.finish(json.dumps(message))