|
|
|
|
@ -2,8 +2,8 @@ from django.shortcuts import render, get_object_or_404 |
|
|
|
|
from django.http import HttpResponse |
|
|
|
|
from django.template import loader |
|
|
|
|
from django.contrib.auth.models import User |
|
|
|
|
from .models import Match, Club, Tournament |
|
|
|
|
from .serializers import UserSerializer, MatchSerializer, ClubSerializer, TournamentSerializer |
|
|
|
|
from .models import Match, Club, Tournament, Team |
|
|
|
|
from .serializers import UserSerializer, MatchSerializer, ClubSerializer, TournamentSerializer, TeamSerializer |
|
|
|
|
from rest_framework import viewsets |
|
|
|
|
from rest_framework import permissions |
|
|
|
|
|
|
|
|
|
@ -41,9 +41,18 @@ def club_name(request, club_name): |
|
|
|
|
} |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
def tournament_club(request, club_name, tournament_id): |
|
|
|
|
def tournament_name(request, tournament_shortname): |
|
|
|
|
tournamentFound = Tournament.objects.filter(shortname__iexact=tournament_shortname.lower()).first() |
|
|
|
|
return tournament(request, tournamentFound.id) |
|
|
|
|
|
|
|
|
|
def club_name_tournament(request, club_name, tournament_id): |
|
|
|
|
return tournament(request, tournament_id) |
|
|
|
|
|
|
|
|
|
def club_name_tournament_name(request, club_name, tournament_shortname): |
|
|
|
|
club = get_object_or_404(Club, name__iexact=club_name.lower()) |
|
|
|
|
tournamentFound = Tournament.objects.filter(club_id=club.id, shortname__iexact=tournament_shortname.lower()).first() |
|
|
|
|
return tournament(request, tournamentFound.id) |
|
|
|
|
|
|
|
|
|
def tournament(request, tournament_id): |
|
|
|
|
|
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
@ -61,12 +70,107 @@ def tournament(request, tournament_id): |
|
|
|
|
def match(request, match_id): |
|
|
|
|
|
|
|
|
|
match = get_object_or_404(Match, pk=match_id) |
|
|
|
|
teams = Team.objects.filter(match=match.id).order_by('position') |
|
|
|
|
template = loader.get_template('scores/match.html') |
|
|
|
|
context = { |
|
|
|
|
'match': match, |
|
|
|
|
'teams': teams, |
|
|
|
|
} |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def teams_tournament_name(request, tournament_shortname): |
|
|
|
|
tournament = get_object_or_404(Tournament, shortname__iexact=tournament_shortname.lower()) |
|
|
|
|
return teams_tournament(request, tournament.id) |
|
|
|
|
|
|
|
|
|
def teams_club_name_tournament(request, club_name, tournament_id): |
|
|
|
|
club = get_object_or_404(Club, name__iexact=club_name.lower()) |
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
return teams_tournament(request, tournament.id) |
|
|
|
|
|
|
|
|
|
def teams_club_name_tournament_name(request, club_name, tournament_shortname): |
|
|
|
|
club = get_object_or_404(Club, name__iexact=club_name.lower()) |
|
|
|
|
tournament = Tournament.objects.filter(club_id=club.id, shortname__iexact=tournament_shortname.lower()).first() |
|
|
|
|
return teams_tournament(request, tournament.id) |
|
|
|
|
|
|
|
|
|
def teams_tournament(request, tournament_id): |
|
|
|
|
|
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
match = Match.objects.filter(tournament=tournament.id).filter(match_index=0).first() |
|
|
|
|
teams = Team.objects.filter(match=match.id).order_by('position') |
|
|
|
|
template = loader.get_template('scores/match.html') |
|
|
|
|
context = { |
|
|
|
|
'match': match, |
|
|
|
|
'teams': teams, |
|
|
|
|
} |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
def tv_index(request): |
|
|
|
|
club = Club.objects.first() |
|
|
|
|
live_matches = Match.objects.filter(enddate__isnull=True).order_by('court') |
|
|
|
|
ended_matches = Match.objects.filter(enddate__isnull=False).order_by('court') |
|
|
|
|
template = loader.get_template('scores/index.html') |
|
|
|
|
context = { |
|
|
|
|
'club': club, |
|
|
|
|
'live_matches': live_matches, |
|
|
|
|
'ended_matches': ended_matches, |
|
|
|
|
'tv': True, |
|
|
|
|
} |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
def tv_tournament_name(request, tournament_shortname): |
|
|
|
|
tournamentFound = Tournament.objects.filter(shortname__iexact=tournament_shortname.lower()).first() |
|
|
|
|
return tv_tournament(request, tournamentFound.id) |
|
|
|
|
|
|
|
|
|
def tv_club_name_tournament(request, club_name, tournament_id): |
|
|
|
|
return tv_tournament(request, tournament_id) |
|
|
|
|
|
|
|
|
|
def tv_club_name_tournament_name(request, club_name, tournament_shortname): |
|
|
|
|
club = get_object_or_404(Club, name__iexact=club_name.lower()) |
|
|
|
|
tournamentFound = Tournament.objects.filter(club_id=club.id, shortname__iexact=tournament_shortname.lower()).first() |
|
|
|
|
return tv_tournament(request, tournamentFound.id) |
|
|
|
|
|
|
|
|
|
def tv_tournament(request, tournament_id): |
|
|
|
|
|
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
live_matches = Match.objects.filter(tournament=tournament.id, enddate__isnull=True).order_by('court') |
|
|
|
|
ended_matches = Match.objects.filter(tournament=tournament.id, enddate__isnull=False).order_by('court') |
|
|
|
|
|
|
|
|
|
template = loader.get_template('scores/tournament.html') |
|
|
|
|
context = { |
|
|
|
|
'tournament': tournament, |
|
|
|
|
'live_matches': live_matches, |
|
|
|
|
'ended_matches': ended_matches, |
|
|
|
|
'tv': True, |
|
|
|
|
} |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
def tv_teams_tournament_name(request, tournament_shortname): |
|
|
|
|
tournament = get_object_or_404(Tournament, shortname__iexact=tournament_shortname.lower()) |
|
|
|
|
return tv_teams_tournament(request, tournament.id) |
|
|
|
|
|
|
|
|
|
def tv_teams_club_name_tournament(request, club_name, tournament_id): |
|
|
|
|
club = get_object_or_404(Club, name__iexact=club_name.lower()) |
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
return tv_teams_tournament(request, tournament.id) |
|
|
|
|
|
|
|
|
|
def tv_teams_club_name_tournament_name(request, club_name, tournament_shortname): |
|
|
|
|
club = get_object_or_404(Club, name__iexact=club_name.lower()) |
|
|
|
|
tournament = Tournament.objects.filter(club_id=club.id, shortname__iexact=tournament_shortname.lower()).first() |
|
|
|
|
return tv_teams_tournament(request, tournament.id) |
|
|
|
|
|
|
|
|
|
def tv_teams_tournament(request, tournament_id): |
|
|
|
|
|
|
|
|
|
tournament = get_object_or_404(Tournament, pk=tournament_id) |
|
|
|
|
match = Match.objects.filter(tournament=tournament.id).filter(match_index=0).first() |
|
|
|
|
teams = Team.objects.filter(match=match.id).order_by('position') |
|
|
|
|
template = loader.get_template('scores/match.html') |
|
|
|
|
context = { |
|
|
|
|
'match': match, |
|
|
|
|
'teams': teams, |
|
|
|
|
'tv': True, |
|
|
|
|
} |
|
|
|
|
return HttpResponse(template.render(context, request)) |
|
|
|
|
|
|
|
|
|
class UserViewSet(viewsets.ModelViewSet): |
|
|
|
|
""" |
|
|
|
|
@ -96,6 +200,14 @@ class MatchViewSet(viewsets.ModelViewSet): |
|
|
|
|
""" |
|
|
|
|
API endpoint that allows matches to be viewed or edited. |
|
|
|
|
""" |
|
|
|
|
queryset = Match.objects.all().order_by('court') |
|
|
|
|
queryset = Match.objects.all().order_by('match_index') |
|
|
|
|
serializer_class = MatchSerializer |
|
|
|
|
permission_classes = [permissions.IsAuthenticated] |
|
|
|
|
|
|
|
|
|
class TeamViewSet(viewsets.ModelViewSet): |
|
|
|
|
""" |
|
|
|
|
API endpoint that allows teams to be viewed or edited. |
|
|
|
|
""" |
|
|
|
|
queryset = Team.objects.all().order_by('id') |
|
|
|
|
serializer_class = TeamSerializer |
|
|
|
|
permission_classes = [permissions.IsAuthenticated] |
|
|
|
|
|