Esempio n. 1
0
def create_game(request):
    game = Game.objects.create()
    player1 = Player.objects.create(user=request.user)
    player1.candidates.add(*all_people())
    game.players.add(player1)
    game.save()
    return HttpResponseRedirect(reverse('games_to_join'))
Esempio n. 2
0
def create_game(request):
    game = Game.objects.create()
    player1 = Player.objects.create(user=request.user)
    player1.candidates.add(*all_people())
    game.players.add(player1)
    game.save()
    return HttpResponseRedirect(reverse('games_to_join'))
Esempio n. 3
0
def join_game(request):
    ctx = {
        'games': Game.objects.annotate(player_count=Count('players'))
                    .filter(player_count=1)
    }

    if request.method == 'POST':
        game_id = request.POST.get('game_id')
        game = Game.objects.get(pk=int(game_id))
        player2 = Player.objects.create(user=request.user)
        player2.candidates.add(*all_people())
        game.players.add(player2)
        game.save()
        return HttpResponseRedirect(reverse('play_game', args=(game.pk,)))

    return render_to_response('core/games_to_join.html', ctx,
                              context_instance=RequestContext(request))
Esempio n. 4
0
def join_game(request):
    ctx = {
        'games':
        Game.objects.annotate(player_count=Count('players')).filter(
            player_count=1)
    }

    if request.method == 'POST':
        game_id = request.POST.get('game_id')
        game = Game.objects.get(pk=int(game_id))
        player2 = Player.objects.create(user=request.user)
        player2.candidates.add(*all_people())
        game.players.add(player2)
        game.save()
        return HttpResponseRedirect(reverse('play_game', args=(game.pk, )))

    return render_to_response('core/games_to_join.html',
                              ctx,
                              context_instance=RequestContext(request))