本文整理匯總了Python中games.models.Game.current_game方法的典型用法代碼示例。如果您正苦於以下問題:Python Game.current_game方法的具體用法?Python Game.current_game怎麽用?Python Game.current_game使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類games.models.Game
的用法示例。
在下文中一共展示了Game.current_game方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: move
# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def move(request, column_number):
game = Game.current_game(request.user)
if game is None:
return Response({"detail": "Not currently in a game."}, 400)
try:
game.move(request.user, column_number)
except IllegalMove as exception:
return Response({"detail": str(exception)}, 400)
return Response(GameSerializer(game).data, 200)
示例2: game_message_list
# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def game_message_list(request):
"""
List all messages for the current game this user is in.
"""
game = Game.current_game(request.user)
if not game:
return Response({"detail": "You are not in a game."}, 400)
game_messages = GameMessage.objects.filter(game=game)
serializer = GameMessageSerializer(game_messages, many=True)
return Response(serializer.data)
示例3: test_leave_stalemate
# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def test_leave_stalemate(self):
self.client.credentials(HTTP_AUTHORIZATION='Token ' + str(self.alice.auth_token))
self.client.post(reverse("games:start"))
self.client.credentials(HTTP_AUTHORIZATION='Token ' + str(self.bob.auth_token))
self.client.post(reverse("games:start"))
game = Game.current_game(self.alice)
game.stalemate = True
game.save()
response = self.client.post(reverse("games:forfeit"))
self.assertEquals(response.status_code, 200)
self.assertEquals(response.data["winner"], None)
示例4: test_create_game_already_in_game
# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def test_create_game_already_in_game(self):
first_game = Game._create_game(self.alice)
second_game = Game._create_game(self.alice)
self.assertEquals(first_game.turn, None)
self.assertEquals(first_game.player1, self.alice)
self.assertEquals(first_game.player2, None)
self.assertEquals(first_game.winner, None)
self.assertEquals(Game.current_game(self.alice), second_game)
self.assertEquals(second_game.turn, None)
self.assertEquals(second_game.player1, self.alice)
self.assertEquals(second_game.player2, None)
self.assertEquals(second_game.winner, None)
示例5: send_game_message
# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def send_game_message(request):
game = Game.current_game(request.user)
if not game:
return Response({"detail": "You are not in a game."}, 400)
data = JSONParser().parse(request)
data["sender"] = request.user.pk
data["pub_date"] = timezone.now()
data["game"] = game.pk
serializer = GameMessageSerializer(data=data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=201)
return Response(serializer.errors, status=400)
示例6: forfeit
# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def forfeit(request):
game = Game.current_game(request.user)
if game is None:
return Response({"detail": "Not currently in a game."}, 400)
game.forfeit(request.user)
return Response(GameSerializer(game).data, 200)