Ejemplo n.º 1
0
def details_inactive(request, tournament_id):
    def get_existing_players_add_form():
        form = ManyPlayersAddForm()
        form.fields['players'].queryset =\
            Player.objects.exclude(signed_to_tournaments = tournament_id)
        return form
    sign_new_player_form = PlayerAddForm()
    sign_existing_players = get_existing_players_add_form()
    if request.method == 'POST':
        if 'button_sign_new' in request.POST:
            sign_new_player_form = PlayerAddForm(request.POST)
            if sign_new_player_form.is_valid():
                player = sign_new_player_form.save()
                p_in_t = PlayersInTournament(player = player, tournament_id = tournament_id)
                p_in_t.save()
        if 'button_sign_existing' in request.POST:
            sign_existing_players = ManyPlayersAddForm(request.POST)
            sign_existing_players.fields['players'].queryset =\
                Player.objects.exclude(signed_to_tournaments = tournament_id)
            if sign_existing_players.is_valid():
                players = sign_existing_players.cleaned_data['players']
                for player in players:
                    if  not PlayersInTournament.objects.filter(
                        tournament_id=tournament_id, player=player).count():
                        p = PlayersInTournament(tournament_id = tournament_id, player = player)
                        p.save()
                        sign_existing_players = get_existing_players_add_form()
    info = get_object_or_404(Tournament, pk=tournament_id, active=False).get_inactive_info()
    return render_to_response('tournament/details_inactive.html', {
        'info' : info,
        'sign_new' : sign_new_player_form,
        'sign_existing' : sign_existing_players
        }, context_instance=RequestContext(request)
    )
Ejemplo n.º 2
0
from Chess.apps.player.models import Player, PlayersInTournament
from Chess.apps.tournament.models import *

t = Tournament(name="deutschland")
t.prize_positions_amount = 1
t.save()
for i in range(1, 25):
    p = Player(name="Vasya" + str(i), elo_rating=50 * i)
    p.save()
    tp = PlayersInTournament(player=p, tournament=t)
    tp.save()
t.create_tours()
tr = t._tours.all()[0]
tr.create_games()