예제 #1
0
def create_sgf(request, tournament_id):
    """Actually create a sgf db entry. Should be called after upload_sgf."""
    tournament = get_object_or_404(Tournament, pk=tournament_id)
    if not tournament.is_admin(request.user):
        raise Http404('What are you doing here?')
    if request.method == 'POST':
        form = SgfAdminForm(request.POST)
        if form.is_valid():
            sgf = Sgf()
            sgf.sgf_text = form.cleaned_data['sgf']
            sgf.p_status = 2
            sgf = sgf.parse()
            check = tournament.check_sgf_validity(sgf)
            if sgf.league_valid:
                sgf.save()
                sgf.update_related([tournament])
                if tournament.stage == 2 and check['match'] is not None:
                    match = check['match']
                    match.sgf = sgf
                    [bplayer, wplayer] = sgf.get_players(tournament)
                    bplayer = TournamentPlayer(pk=bplayer.pk)
                    wplayer = TournamentPlayer(pk=wplayer.pk)
                    if sgf.white == sgf.winner:
                        match.winner = wplayer
                    else:
                        match.winner = bplayer
                    match.save()
                message = " Succesfully created a SGF"
                messages.success(request, message)
            else:
                message = " the sgf didn't seems to pass the tests"
                messages.success(request, message)
    return HttpResponseRedirect(
        reverse('tournament:manage_games',
                kwargs={'tournament_id': tournament.pk}))
예제 #2
0
def upload_sgf(request, tournament_id):
    """THis view allow user to preview sgf with wgo along with valid status of the sgf.
        Can call save_sgf from it.
    """
    tournament = get_object_or_404(Tournament, pk=tournament_id)
    if not tournament.is_admin(request.user):
        raise Http404('What are you doing here?')
    if request.method == 'POST':
        form = SgfAdminForm(request.POST)
        if form.is_valid():
            sgf = Sgf()
            sgf.sgf_text = form.cleaned_data['sgf']
            sgf.p_status = 2
            sgf = sgf.parse()
            check = tournament.check_sgf_validity(sgf)
            form = SgfAdminForm(initial={'sgf': sgf.sgf_text})
            context = {
                'tournament': tournament,
                'sgf': sgf,
                'form': form,
                'match': check['match'],
                'group': check['group']
            }
            template = loader.get_template('tournament/upload_sgf.html')
            return HttpResponse(template.render(context, request))
    else:
        if 'sgf_data' in request.session:
            if request.session['sgf_data'] is None:
                raise Http404("What are you doing here ?")
            sgf = Sgf()
            sgf.sgf_text = request.session['sgf_data']
            request.session['sgf_data'] = None
            sgf.p_status = 2
            sgf = sgf.parse()
            check = tournament.check_sgf_validity(sgf)
            form = SgfAdminForm(initial={'sgf': sgf.sgf_text})
            context = {
                'tournament': tournament,
                'sgf': sgf,
                'form': form,
                'match': check['match'],
                'group': check['group']
            }
            template = loader.get_template('tournament/upload_sgf.html')
            return HttpResponse(template.render(context, request))
        else:
            raise Http404("What are you doing here ?")
예제 #3
0
def forfeit_group(request, tournament_id, group_id):
    tournament = get_object_or_404(Tournament, pk=tournament_id)
    group = get_object_or_404(TournamentGroup, pk=group_id)
    if not tournament.is_admin(request.user):
        raise Http404('What are you doing here?')
    if group.league_event.pk != tournament.pk:
        raise Http404('What are you doing here?')

    if request.method == 'POST':
        form = ForfeitForm(request.POST)
        if form.is_valid():
            winner = get_object_or_404(TournamentPlayer,
                                       pk=form.cleaned_data['winner'])
            looser = get_object_or_404(TournamentPlayer,
                                       pk=form.cleaned_data['looser'])
            sgf = Sgf()
            sgf.winner = winner.user
            sgf.black = winner.user
            sgf.white = looser.user
            sgf.result = "Forfeit"
            sgf.p_status = 0
            sgf.wplayer = looser.user.username
            sgf.bplayer = winner.user.username
            sgf.league_valid = True
            sgf.save()
            sgf.events.add(tournament)
            sgf.divisions.add(group)

            return HttpResponseRedirect(form.cleaned_data['next'])