本文整理汇总了Python中models.Player.status方法的典型用法代码示例。如果您正苦于以下问题:Python Player.status方法的具体用法?Python Player.status怎么用?Python Player.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import status [as 别名]
def post(self):
isAdmin = login.isAdmin()
isPlayer = login.isPlayer()
user = users.get_current_user()
if not isAdmin and not isPlayer:
self.response.set_status(500, message='You must log in')
self.response.out.write('You must log in')
return
# get player data
logging.info(self.request.body)
try:
player_data = json.loads(self.request.body)
except ValueError:
player_data = self.request
logging.info(player_data)
if player_data and player_data.get('id'):
id = int(player_data.get('id'))
db_player = Player.get_by_id(id)
elif player_data.get('name'):
db_player = Player(name=player_data['name'])
else:
self.response.set_status(500, message='You have not specified an id or a name')
self.response.out.write('You have not specified an id or a name')
return
if not isAdmin and db_player.email != user.email():
logging.info(db_player.email)
logging.info(user.email())
self.response.set_status(500, message='You are not authorized')
self.response.out.write('You are not authorized')
return
# edit player in db
if db_player:
status = player_data.get('status') or 'waiting'
# check if status is valid
n_presents = Player.all().filter('status =', 'present').count()
if db_player.status != 'present' and status == 'present' and n_presents >= 10:
logging.info(user.nickname() + ' (' + user.email() +
') tried to set status to \'' + status +
'\' but it was full')
self.response.set_status(500, message='La lista e\' piena')
self.response.out.write('La lista e\' piena')
return
db_player.status = status
if isAdmin:
isStarred = player_data.get('isStarred') == 'True' or False
db_player.isStarred = isStarred
db_player.name = player_data.get('name')
if player_data.get('email'):
db_player.email = player_data.get('email')
db_player.put()
#send message to clients
result = playerToJSON(db_player, isAdmin)
sendMessage(result)
self.response.out.write(result)
else:
self.response.out.write('emptyName')