예제 #1
0
파일: views.py 프로젝트: thran/ufobal-web
def add_match(request):
    data = json.loads(str(request.body.decode('utf-8')))

    tournament = get_object_or_404(Tournament, pk=data.get('tournament'))
    team_one = get_object_or_404(TeamOnTournament, pk=data.get('team_one'))
    team_two = get_object_or_404(TeamOnTournament, pk=data.get('team_two'))
    referee_team = get_object_or_404(TeamOnTournament, pk=data.get('referee_team'))
    if data.get('referee'):
        referee = get_object_or_404(Player, pk=data.get('referee'))
    else:
        referee = None

    if team_one not in tournament.teams.all():
        return HttpResponseBadRequest("První tým není zaregistrovaný na turnaji.")
    if team_two not in tournament.teams.all():
        return HttpResponseBadRequest("Druhý tým není zaregistrovaný na turnaji.")
    if referee_team not in tournament.teams.all():
        return HttpResponseBadRequest("Rozhodčí tým není zaregistrovaný na turnaji.")
    if team_one == team_two or team_one == referee_team or team_two == referee_team:
        return HttpResponseBadRequest("Některý z vybraných týmů se shoduje.")

    match = Match(tournament=tournament, team_one=team_one, team_two=team_two,
                  referee=referee, referee_team=referee_team, start=data.get('start'), place=data.get('place'),
                  end=data.get('end'))
    match.save()

    if data.get('goalie_one'):
        goalie_one = Player.objects.get(pk=data.get('goalie_one'))
        if goalie_one and goalie_one not in team_one.players.all():
            return HttpResponseBadRequest("První brankář se nenachází v prvním týmu.")
        goalie_one_in_match = GoalieInMatch(goalie=goalie_one, match=match, start=datetime.time(0))
        goalie_one_in_match.save()
    elif team_one.default_goalie:
        goalie_one_in_match = GoalieInMatch(goalie=team_one.default_goalie, match=match, start=datetime.time(0))
        goalie_one_in_match.save()

    if data.get('goalie_two'):
        goalie_two = Player.objects.get(pk=data.get('goalie_two'))
        if goalie_two and goalie_two not in team_two.players.all():
            return HttpResponseBadRequest("Druhý brankář se nenachází ve druhém týmu.")
        goalie_two_in_match = GoalieInMatch(goalie=goalie_two, match=match, start=datetime.time(0))
        goalie_two_in_match.save()
    elif team_two.default_goalie:
        goalie_two_in_match = GoalieInMatch(goalie=team_two.default_goalie, match=match, start=datetime.time(0))
        goalie_two_in_match.save()

    return HttpResponse(match.pk)
예제 #2
0
파일: views.py 프로젝트: jojkos/ufobal-web
def add_match(request):
    data = json.loads(str(request.body.decode('utf-8')))

    tournament = get_object_or_404(Tournament, pk=data.get('tournament'))
    team_one = get_object_or_404(TeamOnTournament, pk=data.get('team_one'))
    team_two = get_object_or_404(TeamOnTournament, pk=data.get('team_two'))
    referee_team = get_object_or_404(TeamOnTournament, pk=data.get('referee_team'))
    if data.get('referee'):
        referee = get_object_or_404(Player, pk=data.get('referee'))
    else:
        referee = None

    if team_one not in tournament.teams.all():
        return HttpResponseBadRequest("První tým není zaregistrovaný na turnaji.")
    if team_two not in tournament.teams.all():
        return HttpResponseBadRequest("Druhý tým není zaregistrovaný na turnaji.")
    if referee_team not in tournament.teams.all():
        return HttpResponseBadRequest("Rozhodčí tým není zaregistrovaný na turnaji.")
    if team_one == team_two or team_one == referee_team or team_two == referee_team:
        return HttpResponseBadRequest("Některý z vybraných týmů se shoduje.")

    match = Match(tournament=tournament, team_one=team_one, team_two=team_two,
                  referee=referee, referee_team=referee_team, start=data.get('start'), place=data.get('place'),
                  end=data.get('end'))
    match.save()

    if data.get('goalie_one'):
        goalie_one = Player.objects.get(pk=data.get('goalie_one'))
        if goalie_one and goalie_one not in team_one.players.all():
            return HttpResponseBadRequest("První brankář se nenachází v prvním týmu.")
        goalie_one_in_match = GoalieInMatch(goalie=goalie_one, match=match, start=datetime.time(0))
        goalie_one_in_match.save()
    elif team_one.default_goalie:
        goalie_one_in_match = GoalieInMatch(goalie=team_one.default_goalie, match=match, start=datetime.time(0))
        goalie_one_in_match.save()

    if data.get('goalie_two'):
        goalie_two = Player.objects.get(pk=data.get('goalie_two'))
        if goalie_two and goalie_two not in team_two.players.all():
            return HttpResponseBadRequest("Druhý brankář se nenachází ve druhém týmu.")
        goalie_two_in_match = GoalieInMatch(goalie=goalie_two, match=match, start=datetime.time(0))
        goalie_two_in_match.save()
    elif team_two.default_goalie:
        goalie_two_in_match = GoalieInMatch(goalie=team_two.default_goalie, match=match, start=datetime.time(0))
        goalie_two_in_match.save()

    return HttpResponse(match.pk)
예제 #3
0
파일: views.py 프로젝트: thran/ufobal-web
def match_add(request, tournament_id):
    tournament = get_object_or_404(Tournament.objects, id=tournament_id)
    team_one_id = request.POST.get("team_one")
    team_one = get_object_or_404(TeamOnTournament.objects, id=team_one_id)
    team_two_id = request.POST.get("team_two")
    team_two = get_object_or_404(TeamOnTournament.objects, id=team_two_id)

    if team_one.tournament != tournament or team_two.tournament != tournament:
        messages.warning(request, "Nemůžete vytvořit zápas s týmem co nehraje na turnaji")
        return redirect("managestats:tournament", tournament_id=tournament_id)
    if team_one == team_two:
        messages.warning(request, "Nemůžete vytvořit zápas se dvěma stejnými týmy")
        return redirect("managestats:tournament", tournament_id=tournament_id)

    match = Match(tournament=tournament, team_one=team_one, team_two=team_two)
    match.save()

    messages.success(request, "Zápas přidán: {}".format(match))
    return redirect("managestats:tournament", tournament_id=tournament_id)
예제 #4
0
파일: views.py 프로젝트: jojkos/ufobal-web
def match_add(request, tournament_id):
    tournament = get_object_or_404(Tournament.objects, id=tournament_id)
    team_one_id = request.POST.get("team_one")
    team_one = get_object_or_404(TeamOnTournament.objects, id=team_one_id)
    team_two_id = request.POST.get("team_two")
    team_two = get_object_or_404(TeamOnTournament.objects, id=team_two_id)

    if team_one.tournament != tournament or team_two.tournament != tournament:
        messages.warning(
            request, 'Nemůžete vytvořit zápas s týmem co nehraje na turnaji')
        return redirect("managestats:tournament", tournament_id=tournament_id)
    if team_one == team_two:
        messages.warning(request,
                         'Nemůžete vytvořit zápas se dvěma stejnými týmy')
        return redirect("managestats:tournament", tournament_id=tournament_id)

    match = Match(tournament=tournament, team_one=team_one, team_two=team_two)
    match.save()

    messages.success(request, 'Zápas přidán: {}'.format(match))
    return redirect("managestats:tournament", tournament_id=tournament_id)