예제 #1
0
def edit_game(request, game_id):
    school = get_school(request)
    game = get_object_or_404(Game, id=game_id)
    if not check_auth(school, game):
        return HttpResponse("Game wasn't played by your school", status=403)
    if not game.match.round.season in CurrentSeasons.objects.get():
        return HttpResponseBadRequest("Can't edit games from old seasons")

    submitted_data = json.loads(request.body)
    try:
        player = Player.objects.get(name=submitted_data['player_name'], school=school)
    except Player.DoesNotExist:
        return HttpResponseBadRequest('Couldn\'t find player')

    if game.match.team1.school == school:
        valid_roster = game.match.team1.players.all()
    else:
        valid_roster = game.match.team2.players.all()

    if not player in valid_roster:
        return HttpResponseBadRequest("Submitted player is not in current roster")

    if game.match.team1.school == school:
        game.team1_player = player
    else:
        game.team2_player = player

    game.save()

    return HttpResponse("success")
예제 #2
0
def create_player(request):
    school = get_school(request)
    if request.method == 'GET':
        form = EditPlayerForm()
    elif request.method == 'POST':
        form = EditPlayerForm(request.POST)
        if form.is_valid():
            new_player = Player(school=school, **form.cleaned_data)
            new_player.save()
            return redirect('captain_dashboard')
    return render(request, 'create_player.html', locals())
예제 #3
0
def edit_player(request, player_id):
    school = get_school(request)
    player = get_object_or_404(Player, id=player_id)
    if not check_auth(school, player):
        raise PermissionDenied

    if request.method == 'POST':
        form = EditPlayerForm(request.POST, instance=player)
        if form.is_valid():
            form.save()
    else:
        form = EditPlayerForm(instance=player)
    return render(request, 'edit_player.html', locals())
예제 #4
0
def edit_school(request, school_slug):
    school_authed = get_school(request)
    school = get_object_or_404(School, slug_name=school_slug)
    if not check_auth(school_authed, school):
        raise PermissionDenied

    if request.method == 'POST':
        form = EditSchoolForm(request.POST, instance=school)
        if form.is_valid():
            form.save()
    else:
        form = EditSchoolForm(instance=school)
    return render(request, 'edit_school.html', locals())
예제 #5
0
def edit_matches_for_seasons(request, season_names):
    school = get_school(request)
    season_matches = Match.objects.none()
    for season in (Season.objects.get(name=s) for s in season_names):
        season_matches = season_matches | Match.objects.filter(round__season=season)

    relevant_matches = [m for m in season_matches
            if m.round.in_past()
            and (m.team1.school == school
                 or m.team2.school == school)]

    all_seasons = Season.objects.all()
    return render(request, 'edit_season.html', locals())
예제 #6
0
def edit_team(request, team_id):
    school = get_school(request)
    team = get_object_or_404(Team, id=team_id)
    if not check_auth(school, team):
        raise PermissionDenied

    if request.method == 'POST':
        form = EditTeamForm(request.POST, instance=team)
        if form.is_valid():
            form.save()
    else:
        form = EditTeamForm(instance=team)
    form.fields['players'].queryset = school.player_set.all_but_unknown()
    return render(request, 'edit_team.html', locals())
예제 #7
0
def edit_match(request, match_id):
    school = get_school(request)
    all_players = Player.objects.filter(school=school)
    match = get_object_or_404(Match, id=match_id)
    school_is_team1 = match.team1.school == school
    return render(request, 'edit_match.html', locals())
예제 #8
0
def captain_dashboard(request):
    school = get_school(request)
    all_teams = Team.objects.filter(school=school, season__in=CurrentSeasons.objects.get())
    return render(request, 'captain_dashboard.html', locals())