本文整理汇总了Python中models.Game.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Game.get_by_id方法的具体用法?Python Game.get_by_id怎么用?Python Game.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: replay
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def replay(self, request):
game = Game.get_by_id(request.id)
if not game:
raise endpoints.NotFoundException
game.reset()
game.put()
return game.to_message()
示例2: DoPost
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def DoPost(self):
game = Game.get_by_id(long(self.request.get('game_id')))
if not (game.player_1.key() == self.player.key() or
game.player_2.key() == self.player.key()):
raise Exception("You can't complete a game you don't own, duderino!")
if game.completed_date != None:
raise Exception("You can't complete a game that's already been completed, duderino!")
player_1_won = bool(self.request.get('player_1_won'))
player_2_won = bool(self.request.get('player_2_won'))
if not player_1_won ^ player_2_won:
raise "One player, and only one player, can win a game."
game.completed_date = datetime.now()
if player_1_won:
game.winner = game.player_1
else:
game.winner = game.player_2
update_ranks(game)
game.player_1.put()
game.player_2.put()
game.put()
logging.info("Player %s completed game %s" % (self.player, game))
self.redirect_to_redirect_path_or_home()
示例3: kill
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def kill():
try:
msg = request.json["msg"].upper()
killer = Player.all().filter('username =', request.json["username"]).get()
game = Game.get_by_id(int(request.json["game_id"]))
old_game_history_success = GameHistory.all()\
.filter('game =', game)\
.filter('killer =', killer)\
.filter('is_complete =', False).get()
if msg == old_game_history_success.confirm_msg:
will_be_last_kill = None
if GameHistory.all().filter("game =", game).filter("is_complete =", False).count() == 2:
will_be_last_kill = True
old_target = old_game_history_success.target
old_game_history_success.is_complete = True
old_game_history_success.put()
old_game_history_failure = GameHistory.all()\
.filter('game =', game)\
.filter('killer =', old_target)\
.filter('is_complete =', False).get()
old_game_history_failure.is_complete = True
old_game_history_failure.put()
if will_be_last_kill:
game_player = GamePlayer.all().filter('game =', game).filter('player =', killer).get()
game_player.is_winner = True
game_player.put()
return jsonify({"success": True, "info": "Your enemy has been slain! "})
new_target = old_game_history_failure.target
GameHistory(killer=killer, target=new_target, game=game, is_complete=False, confirm_msg=msg_generator()).put()
return jsonify({"success": True, "info": "Your enemy has been slain! "})
else:
return jsonify({"success": False, "info": "The message is incorrect. Are you trying to game the system?!"})
except: # TODO: please handle exceptions in a more proper way
return jsonify({"success": False, "info": "Something is fundamentally wrong. ", "Data received by server": str(request.data)})
示例4: move
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def move(self, request):
game = Game.get_by_id(request.id)
square = request.square
if not game:
raise endpoints.NotFoundException
if game.outcome is not None:
raise endpoints.BadRequestException
if square not in Squares.ALL:
raise endpoints.BadRequestException
if not game.is_empty_square(square):
raise endpoints.BadRequestException
setattr(game, square, 'X')
if game.is_won('X'):
game.outcome = Game.WON
elif game.is_tied():
game.outcome = Game.TIED
else:
setattr(game, game.get_best_square(), 'O')
if game.is_won('O'):
game.outcome = Game.LOST
game.put()
return game.to_message()
示例5: editar_form
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def editar_form(jogo_id):
jogo_id = int(jogo_id)
jogo=Game.get_by_id(jogo_id)
jogo_form = GameForm()
jogo_form.fill_with_model(jogo)
contexto = {'editar_path': router.to_path(atualizar, jogo_id),
'game' : jogo_form}
return TemplateResponse(contexto, 'temporario/forme.html')
示例6: editar_form
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def editar_form(jogo_id):
jogo_id = int(jogo_id)
jogo=Game.get_by_id(jogo_id)
jogo_form=GameForm()
jogo_form.fill_with_model(jogo)
contexto={'salvar_path': router.to_path(salvar, jogo_id),
'jogo':jogo_form}
return TemplateResponse(contexto, 'editar/home.html')
示例7: index
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def index(_logged_user, game_id):
game = Game.get_by_id(long(game_id))
quests = Quest.query().fetch()
quest_list = [quest.to_dict(exclude=["jog"]) for quest in quests if quest.jog.id() == game.key.id()]
dict_ = {
'game': json.dumps(game.to_dict()),
'quests': json.dumps(quest_list)
}
return TemplateResponse(context=dict_, template_path="jogar/jogar.html")
示例8: upload
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def upload(_handler, **jogos_properties):
if jogos_properties.get('files'):
blob_infos = _handler.get_uploads("files[]")
blob_key = blob_infos[0].key()
avatar = router.to_path(download, blob_key)
cmd = Game.get_by_id(long(jogos_properties['id']))
cmd.foto = avatar
cmd.put()
return RedirectResponse(router.to_path(index))
示例9: get_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def get_game(game_id):
game = Game.get_by_id(int(game_id))
if game is None:
return jsonify({'success': False, 'info': None})
info = to_dict(game)
people = [game_player.player.username for game_player in game.players]
info['success'] = True
info['participants'] = str(people)
game_history = GameHistory.all().filter('game =', game).filter('is_complete =', False)
info['survivors'] = [record.killer.username for record in game_history]
return jsonify({'success': True, 'info': info}) # does not render a page, just returns a Json
示例10: analise
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def analise(game_id):
game = Game.get_by_id(long(game_id))
query = Result.query(Result.game == game.key).order(-Result.best_points).order(-Result.won_medal)
results_lista = query.fetch()
results = []
for result in results_lista:
user = Node.get_by_id(long(result.user.id()))
result_dict = result.to_dict()
result_dict['user_name'] = user.name
results.append(result_dict)
return TemplateResponse({"results": results, "game_id": game_id}, template_path="gerenciar/analise.html")
示例11: add
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def add(question, answer, game_id, id=None):
game = Game.get_by_id(long(game_id))
if game is None:
raise Exception("game id: %s not found" % game_id)
if id is not None:
quest = Quest.get_by_id(long(id))
quest.answer = answer
quest.question = question
quest_key = quest.put()
else:
quest_key = Quest(question=question, answer=answer, jog=game.key).put()
return json.dumps({"quest_id": quest_key.id()})
示例12: atualizar
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def atualizar(jogo_id, **propriedades):
jogo_id = int(jogo_id)
jogo = Game.get_by_id(jogo_id)
game_form = GameForm(**propriedades)
erros = game_form.validate()
if erros:
contexto = {'editar_path': router.to_path(salvar),
'game': game_form,
'erros': erros}
return TemplateResponse(contexto, 'temporario/form.html')
else:
game_form.fill_model(jogo)
jogo.put()
return RedirectResponse(router.to_path(index))
示例13: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def get(self):
uid = self.get_argument('uid', '')
gid = self.get_argument('gid', '')
if gid == '':
self.write('{"error":"gid parameter need"}')
return
o = Game.get_by_id(gid)
if o == None:
self.write(json.dumps({'error': "not found", 'gid': gid}))
return
data = {}
data['game'] = o.to_dict(uid, True)
self.write(json.dumps(data))
示例14: post
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def post(self, gameid):
user = auth()
if user == None:
logging.debug("CreateGame: Entered unauthenticated user!!")
self.response.out.write(json.dumps({'error': 'No autheticated user'}))
return
# Check to see if the game is still active
game = Game.get_by_id(int(gameid))
if not game.active:
self.response.out.write(json.dumps({'error': 'Game seems to have ended. Join some other game'}))
else:
game.players.append(user)
game.put()
user.activeGame = game
user.put()
示例15: get_game_status
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_by_id [as 别名]
def get_game_status():
info = {"target": None, "in_game": False, "game_exists": False, "msg": None, "player_exists": False, "game_completed": False, "time_left": None}
try:
game = Game.get_by_id(int(request.args["game_id"]))
if game is None:
info["msg"] = "Game does not exists. "
return jsonify(info)
info["game_exists"] = True
killer = Player.all().filter('username =', request.args["username"]).get()
if killer is None:
info["msg"] = "Player trying to kill does not exist. "
return jsonify(info)
info["player_exists"] = True
player_in = GamePlayer.all().filter('game =', game).filter('player =', killer).get()
if player_in is None:
info["msg"] = "Player trying to kill is not in this game. "
return jsonify(info)
info["in_game"] = True
if GameHistory.all().filter("game =", game).filter("is_complete =", False).count() == 0:
info["game_completed"] = True
game_player = GamePlayer.all().filter('game =', game).filter('is_winner =', True).get()
info["winner_name"] = str(game_player.player.username)
return jsonify(info)
to_kill_game_history = GameHistory.all().filter('killer =', killer).filter('game =', game).filter('is_complete', False).get()
be_killed_game_history = GameHistory.all().filter('target =', killer).filter('game =', game).filter('is_complete', False).get()
if to_kill_game_history is None:
return jsonify(info)
else:
info["time_left"] = to_kill_game_history.assign_date + timedelta(hours=1)
info["target"] = to_kill_game_history.target.username
info["msg"] = be_killed_game_history.confirm_msg
return jsonify(info)
except:
# info["time_left"] = str(datetime.datetime.now())
info["msg"] = "Something is fundamentally wrong. "
return jsonify(info)