Esempio n. 1
0
def tournament_add(request):
    form = forms.TournamentForm(request.POST or None)
    ParticipantFormSet = formset_factory(forms.ParticipantForm, extra=3)
    formset = ParticipantFormSet(request.POST or None, prefix='participant')
    if form.is_valid() and formset.is_valid():
        tournament = form.save(commit=False)
        tournament.user = request.user
        tournament.save()
        for form_from_formset in formset:
            participant = form_from_formset.save(commit=False)
            participant.tournament = tournament
            participant.save()
        tournament.round_count = recommended_tour_count(tournament.members.count())
        tournament.save()
        return redirect('home')
    return render(request, 'front/tournament_add.html', locals())
Esempio n. 2
0
def for_test(request):
    t = Tournament(title='test for test')
    t.round_count = recommended_tour_count(9)
    t.user = request.user
    t.save()
    for i in range(1,10):
        chp = Chessplayer(name=str(i)+'name', rate=i*20)
        chp.save()
        p = Participant(tournament = t, chessplayer = chp, )
        p.save()
    t.proceed()
    #for i in range(1, recommended_tour_count(9)):
    #    n = 1
    #    fl = True
    #    for j in Participant.objects.filter(tournament=t):
    #        r = Record(round=i, couple=n, participant=j, tournament=t, result=0.5)
    #        if not fl: n +=1
    #        fl = not fl
    #        r.save()
    return redirect('home')