本文整理汇总了Python中models.Player.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Player.get_by_id方法的具体用法?Python Player.get_by_id怎么用?Python Player.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.get_by_id方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def get(self, request, player_id=None):
if player_id==None:
data = [model_to_dict(i) for i in Player.get_all()]
return HttpResponse(json.dumps(data))
player = Player.get_by_id(player_id)
player = model_to_dict(player)
return HttpResponse(json.dumps({"player": player}))
示例2: get_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def get_player(player_id):
player = Player.get_by_id(player_id)
game_players = GamePlayer.all().filter('player =', player)
games = [game_player.game for game_player in game_players]
info = {}
for game in games:
info[str(game.key().id())] = to_dict(game)
return jsonify(**info)
示例3: get
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def get(self, playerId):
player = Player.get_by_id(int(playerId))
if player:
values = {"player":player}
path = os.path.join(os.path.dirname(__file__), 'templates/edit_player.html')
else:
values = { "message" : "Error finding player."}
path = os.path.join(os.path.dirname(__file__), 'templates/success.html')
self.response.out.write(template.render(path, values))
示例4: get_player_from_email
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def get_player_from_email(email):
"""Helper method to get the Player object corresponding to the given User.
Creates a new Player object if one didn't exist already.
"""
email = email.lower()
player = Player.get_by_id(email, parent=get_parent_key_from_email(email))
logging.info("player = " + str(player))
if not player:
logging.info("Failed to find player by id, creating new user")
player = Player(parent=get_parent_key_from_email(email), id=email)
player.put()
return player
示例5: put
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def put(self, id):
isActive = Configuration.all().filter('name', 'checkin').get()
isAdmin = login.isAdmin()
isPlayer = login.isPlayer() and not isAdmin
user = users.get_current_user()
if not isAdmin and not isPlayer:
self.response.out.write('not_logged_in')
else:
request = json.loads(self.request.body)
status = request['status']
n_presents = Player.all().filter('status =', 'present').count()
if status != 'present' or n_presents < 10:
player = None
if isAdmin:
id = long(id)
player = Player.get_by_id(id)
logging.info('Admin set status to \'' + status + '\' for ' +
str(player.email))
elif isPlayer and (isActive is None or isActive.value):
player = Player.all()
player = player.filter('email =', user.email()).get()
logging.info(str(player.email) + ' set status to \'' +
status + '\'')
if player:
player.status = status
player.put()
#self.response.out.write('ok')
else:
logging.info(user.nickname() + ' (' + user.email() +
') tried to set status to \'' +
status + '\' but it was inactive')
self.response.set_status(401, 'La lista è bloccata o \
non sei più loggato')
else:
logging.info(user.nickname() + ' (' + user.email() +
') tried to set status to \'' + status +
'\' but it was full')
self.response.set_status(500, 'La lista è piena')
示例6: delete
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def delete(self):
if login.isAdmin():
#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)
if db_player:
db_player.delete()
result = playerToJSON(db_player, True)
self.response.out.write(result)
#send message to clients
sendMessage(result)
else:
self.response.out.write('player not found')
示例7: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def post(self):
request_data = json.loads(self.request.body)
logging.info(request_data)
player = current_user_player()
kicked_player = Player.get_by_id(request_data['player_id'])
team = kicked_player.team.get()
# VALIDATIONS
if not validate_is_team_owner(self.response, player, team):
return
if player == kicked_player:
error_400(self.response, "ERROR_CANT_KICK_SELF", "You cannot kick yourself from your own team. Are you retarded?")
return
# DO SHIT
kicked_player.team = None
kicked_player.put()
websocket_notify_player("Player_KickedFromTeam", kicked_player.key, "player", {'team': None})
_websocket_notify_team("Team_KickedMember", team.key, "player.team.members.-[%s]" % kicked_player.key.id(), kicked_player.get_data_nick_and_id())
set_json_response(self.response, {'code': "OK"})
示例8: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [as 别名]
def post(self, playerId):
deleteClicked = self.request.get("delete")
player = Player.get_by_id(int(playerId))
if player:
if deleteClicked:
player.delete()
values = { "message" : "Player deleted successfully."}
else:
#TODO: optimize this... if values are equal, don't post
player.fname = self.request.get("fname%s" % playerId)
player.lname = self.request.get("lname%s" % playerId)
player.email = self.request.get("email%s" % playerId)
phone = self.request.get("phone%s" % playerId)
if phone:
player.phone = phone
inOrOut = self.request.get("inOrOut")
if inOrOut == "in":
player.inThisWeek = True
else:
player.inThisWeek = False
playerType = self.request.get("playerType")
logging.info(playerType)
if playerType == "goalie":
player.goalie = True
else:
player.goalie = False
regularOrSub = self.request.get("regularOrSub")
if regularOrSub == "sub":
player.sub = True
else:
player.sub = False
player.put()
memcache.delete('players')
values = { "message" : "Changes have been saved successfully."}
else:
values = { "message" : "Error finding player."}
path = os.path.join(os.path.dirname(__file__), 'templates/success.html')
self.response.out.write(template.render(path, values))
示例9: post
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get_by_id [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')