diff --git a/tournaments/templates/tournaments/tournament_stream.html b/tournaments/templates/tournaments/tournament_stream.html new file mode 100644 index 0000000..04b96c5 --- /dev/null +++ b/tournaments/templates/tournaments/tournament_stream.html @@ -0,0 +1,142 @@ +{% load static %} + + + + + + + + + + Padel + + + + + + + + + +
+
+
+
+
+
+ +
+

4Padel Toulouse

+

Planning

+ +
+
+
+
+ + + +
+
+
+ + + diff --git a/tournaments/urls.py b/tournaments/urls.py index 8a24f7e..78d6b64 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -1,9 +1,19 @@ -from django.urls import path +from django.urls import include, path from . import views urlpatterns = [ + path("", views.index, name="index"), - path('tournament//', views.tournament, name='tournament'), - path('tournament//planning/', views.tournament_planning, name='tournament-planning'), + + # Tournament + path("tournament//", + include( + [ + path("", views.tournament, name="tournament"), + path("planning/", views.tournament_planning, name="tournament-planning"), + path("stream/", views.tournament_stream, name="tournament-stream"), + ] + ) + ) ] diff --git a/tournaments/views.py b/tournaments/views.py index 5270c66..30ae09b 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -1,5 +1,6 @@ +#coding:utf-8 + from django.shortcuts import render, get_object_or_404 -from django.http import HttpResponse from .serializers import ClubSerializer, TournamentSerializer, ExpandedTournamentSerializer, UserSerializer, ChangePasswordSerializer, EventSerializer, RoundSerializer, GroupStageSerializer, MatchSerializer, TeamStateSerializer, TeamRegistrationSerializer, PlayerRegistrationSerializer from .models import Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamState, TeamRegistration, PlayerRegistration from .models import TeamCall @@ -10,21 +11,20 @@ from rest_framework.response import Response from rest_framework.decorators import api_view from rest_framework import status from rest_framework.generics import UpdateAPIView -from django.template import loader from datetime import date + +# TODO: 1 app core (avec les models), 1 app web, 1 app API pour séparer les views + +## +# Web UI +## + def index(request): today = date.today() future_tournaments = Tournament.objects.filter(end_date__isnull=True, start_date__gt=today).order_by('start_date') live_tournaments = Tournament.objects.filter(end_date__isnull=True, start_date__lte=today).order_by('start_date') ended_tournaments = Tournament.objects.filter(end_date__isnull=False).order_by('start_date') - # template = loader.get_template('tournaments/tournaments.html') - # context = { - # 'future': future_tournaments, - # 'live': live_tournaments, - # 'ended': ended_tournaments, - # } - # return HttpResponse(template.render(context, request)) return render( request, "tournaments/tournaments.html", @@ -38,31 +38,31 @@ def index(request): def tournament(request, tournament_id): - tournament = get_object_or_404(Tournament, pk=tournament_id) today = date.today() - future_matches = Match.objects.filter(end_date__isnull=True, start_date__gt=today).order_by('start_date') live_matches = Match.objects.filter(end_date__isnull=True, start_date__lte=today).order_by('start_date') ended_matches = Match.objects.filter(end_date__isnull=False).order_by('start_date') - template = loader.get_template('tournaments/tournament.html') context = { 'future': future_matches, 'live': live_matches, 'ended': ended_matches, } - return HttpResponse(template.render(context, request)) + return render(request, "tournaments/tournament.html", context) -def tournament_planning(request, tournament_id): +def tournament_planning(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) team_calls = tournament.team_calls() + context = {'team_calls': team_calls} + return render(request, "tournaments/planning.html", context) - template = loader.get_template('tournaments/planning.html') - context = { - 'team_calls': team_calls, - } - return HttpResponse(template.render(context, request)) + +def tournament_stream(request, tournament_id): + tournament = get_object_or_404(Tournament, pk=tournament_id) + return render(request, "tournaments/tournament_stream.html", { + "tournament": tournament, + }) # def index(request): @@ -77,6 +77,11 @@ def tournament_planning(request, tournament_id): # } # return HttpResponse(template.render(context, request)) + +## +# API +## + @api_view(['GET']) def user_by_token(request): # return Response({"message": "Hello for today! See you tomorrow!"}) @@ -143,3 +148,4 @@ class TeamRegistrationViewSet(viewsets.ModelViewSet): class PlayerRegistrationViewSet(viewsets.ModelViewSet): queryset = PlayerRegistration.objects.all() serializer_class = PlayerRegistrationSerializer +