本文整理汇总了Python中models.Match.create_match方法的典型用法代码示例。如果您正苦于以下问题:Python Match.create_match方法的具体用法?Python Match.create_match怎么用?Python Match.create_match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.create_match方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_match
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create_match [as 别名]
def create_match(self, request):
""" Creates a new match.
This match allows players to create a new match. A match is an
'instance' of a game. This allows multiple users to play the same
game at the same time or different times.
Returns:
StringMessage -- a confirmation that the match has been created
Raises:
BadRequestException -- raised when game has no questions or when
game is not in play mode or when play mode
enabling is required, but was not requested
"""
# Get game and player from datastore
game = get_by_urlsafe(request.urlsafe_game_key, Game)
player = get_player(request.user_name)
# Check if game has questions. A game with no questions is not playable
if game.questions == []:
raise endpoints.BadRequestException(
'The game has no questions yet and cannot be played.')
# Check if game has been changed from editing to play mode
if not game.play_mode:
# Only game creators can put a game into play mode
if player.key != game.creator:
raise endpoints.BadRequestException(
'Only the game creator can put it into play mode.')
else:
# Check if creator has explicitly requested to start the game
if not request.start_game:
raise endpoints.BadRequestException(
'Play mode enabling was not requested.')
else:
# Put game into play mode and save the change
game.play_mode = True
game.put()
# Create the match
match = Match.create_match(player=player.key, game=game)
# Return a confirmation of the match creation
return match.to_form()