Exemplo n.º 1
0
def make_move(request, game_id):
    """ persist the move if available """
    game = get_object_or_404(Game, pk=game_id)
    if not game.is_users_move(request.user):
        raise PermissionDenied
    move = game.new_move()
    form = MoveForm(instance=move, data=request.POST)
    if form.is_valid:
        form.save()
        return redirect(game)
    else:
        return render(request, 'gameplay/game_detail.html', {
            'game': game,
            'form': form
        })
Exemplo n.º 2
0
def make_move(request, id):

    game = get_object_or_404(Game, pk=id)

    if not game.is_users_move(request.user):
        raise PermissionError

    move = game.new_move()
    form = MoveForm(instance=move, data=request.POST)

    if form.is_valid():
        game.save()
        form.save()
        return redirect("gameplay_detail", id)
    else:
        return render(request, "gameplay/game_detail.html", {
            'game': game,
            'form': form
        })