Tournament stream

Nicolas Ferrari 2 years ago
parent 84f1f7209c
commit 3a54e398e4
  1. 142
      tournaments/templates/tournaments/tournament_stream.html
  2. 16
      tournaments/urls.py
  3. 44
      tournaments/views.py

@ -0,0 +1,142 @@
{% load static %}
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="{% static 'tournaments/css/foundation.min.css' %}" />
<link rel="stylesheet" href="{% static 'tournaments/css/style.css' %}" />
<link rel="icon" type="image/png" href="{% static 'tournaments/images/favicon.png' %}" />
<title>Padel</title>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
</head>
<!--
TODO: utiliser le nom de l'URL pour le fetch {% url "monurl" tournament.pk %}?format=json
-->
<body x-data="{
tournament: null,
active: 1,
screens: 2,
retrieveTournament() {
fetch('/api/exp-tournaments/{{ tournament.pk }}/?format=json')
.then(res => res.json())
.then((data) => {
this.tournament = data
})
},
loop() {
this.retrieveTournament()
setInterval(() => {
this.retrieveTournament()
this.active = this.active === this.screens ? 1 : this.active+1
}, 3000)
}
}" x-init="loop()">
<div class="wrapper">
<main class="page-body">
<div class="container">
<div class="grid-x">
<div class="cell medium-6 large-6 topblock my-block">
<div class="bubble">
<img
src="{% static 'tournaments/images/PadelClub_logo_512.png' %}"
class="logo inline"
/>
<div class="inline">
<h1 class="club">4Padel Toulouse</h1>
<h1 class="event">Planning</h1>
<!-- <span>Propulsé par Padel Club</span> -->
</div>
</div>
</div>
</div>
<template x-if="tournament">
<div class="grid-x padding-bottom">
<div class="cell medium-6 large-6 topblock my-block">
<div class="bubble" x-show="active === 1">
<label class="title">Équipes</label>
<template x-for="team in tournament.teamregistration_set" >
<div class="table-container bottom-border vertical-padding">
<img src="{% static 'tournaments/images/pc_icon_round_200.png' %}" class="team_image horizontal-margin">
<div class="w50 tight table-cell hpadding10">
<template x-for="player in team.playerregistration_set">
<div>
<div x-text="player.first_name"></div> <div x-text="player.last_name"></div>
</div>
</template>
</div>
<div class="table-cell horizontal-padding">
<span x-text="team.court"></span>
</div>
<div class="table-cell horizontal-padding large">
<span x-text="team.call_date"></span>
</div>
<div class="table-cell"><div class="mybox">Poule A</div></div>
</div>
</template>
</div>
<div class="bubble" x-show="active === 2">
<label class="title">Matchs</label>
<template x-for="round in tournament.round_set">
<template x-for="match in round.match_set">
<div>
<div class="flex-row">
<label class="left-label matchtitle">{{ match.id }}</label>
<label class="right-label info">{{ match.start_date }}</label>
</div>
<div>
{% for team in match.team_states %}
<div class="test bottom-border padding-bottom-small">
<div class="left-label">
{% for name in team.names %}
<div class="winner">
{{ name }}
</div>
{% endfor %}
</div>
<div class="">
{% for score in team.scores %}
<span class="score ws {% if team.is_winner %}winner{% endif %}">{{ score }}</span>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<div class="top-margin flex-row">
<label class="left-label minor-info">{{ match.duration }}</label>
<!-- <a href="" class="right-label">détails</a> -->
</div>
</div>
</template>
</template>
</div>
</div>
</div>
</template>
</div>
</main>
</div>
</body>
</html>

@ -1,9 +1,19 @@
from django.urls import path from django.urls import include, path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path('tournament/<str:tournament_id>/', views.tournament, name='tournament'),
path('tournament/<str:tournament_id>/planning/', views.tournament_planning, name='tournament-planning'), # Tournament
path("tournament/<str:tournament_id>/",
include(
[
path("", views.tournament, name="tournament"),
path("planning/", views.tournament_planning, name="tournament-planning"),
path("stream/", views.tournament_stream, name="tournament-stream"),
]
)
)
] ]

@ -1,5 +1,6 @@
#coding:utf-8
from django.shortcuts import render, get_object_or_404 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 .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 Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamState, TeamRegistration, PlayerRegistration
from .models import TeamCall from .models import TeamCall
@ -10,21 +11,20 @@ from rest_framework.response import Response
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework import status from rest_framework import status
from rest_framework.generics import UpdateAPIView from rest_framework.generics import UpdateAPIView
from django.template import loader
from datetime import date 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): def index(request):
today = date.today() today = date.today()
future_tournaments = Tournament.objects.filter(end_date__isnull=True, start_date__gt=today).order_by('start_date') 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') 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') 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( return render(
request, request,
"tournaments/tournaments.html", "tournaments/tournaments.html",
@ -38,31 +38,31 @@ def index(request):
def tournament(request, tournament_id): def tournament(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id) tournament = get_object_or_404(Tournament, pk=tournament_id)
today = date.today() today = date.today()
future_matches = Match.objects.filter(end_date__isnull=True, start_date__gt=today).order_by('start_date') 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') 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') ended_matches = Match.objects.filter(end_date__isnull=False).order_by('start_date')
template = loader.get_template('tournaments/tournament.html')
context = { context = {
'future': future_matches, 'future': future_matches,
'live': live_matches, 'live': live_matches,
'ended': ended_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) tournament = get_object_or_404(Tournament, pk=tournament_id)
team_calls = tournament.team_calls() 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 = { def tournament_stream(request, tournament_id):
'team_calls': team_calls, tournament = get_object_or_404(Tournament, pk=tournament_id)
} return render(request, "tournaments/tournament_stream.html", {
return HttpResponse(template.render(context, request)) "tournament": tournament,
})
# def index(request): # def index(request):
@ -77,6 +77,11 @@ def tournament_planning(request, tournament_id):
# } # }
# return HttpResponse(template.render(context, request)) # return HttpResponse(template.render(context, request))
##
# API
##
@api_view(['GET']) @api_view(['GET'])
def user_by_token(request): def user_by_token(request):
# return Response({"message": "Hello for today! See you tomorrow!"}) # return Response({"message": "Hello for today! See you tomorrow!"})
@ -143,3 +148,4 @@ class TeamRegistrationViewSet(viewsets.ModelViewSet):
class PlayerRegistrationViewSet(viewsets.ModelViewSet): class PlayerRegistrationViewSet(viewsets.ModelViewSet):
queryset = PlayerRegistration.objects.all() queryset = PlayerRegistration.objects.all()
serializer_class = PlayerRegistrationSerializer serializer_class = PlayerRegistrationSerializer

Loading…
Cancel
Save