From de3417b0d988c0ebef34311ad1f9ce77fbf03048 Mon Sep 17 00:00:00 2001 From: Laurent Date: Sat, 9 Mar 2024 17:50:35 +0100 Subject: [PATCH] display matches --- static/tournaments/css/style.css | 27 ++- static/tournaments/test.html | 164 ++++++++++++++++++ ...ition_teamregistration_bracket_position.py | 18 ++ .../migrations/0017_alter_match_court.py | 18 ++ tournaments/models.py | 62 ++++--- tournaments/serializers.py | 7 +- tournaments/static/tournaments/Padeltest.html | 8 +- tournaments/static/tournaments/css/style.css | 28 ++- tournaments/static/tournaments/test.html | 164 ++++++++++++++++++ tournaments/templates/tournaments/base.html | 13 +- .../templates/tournaments/match_cell.html | 79 +++++---- .../templates/tournaments/matches.html | 28 +-- tournaments/views.py | 37 ++-- 13 files changed, 537 insertions(+), 116 deletions(-) create mode 100644 static/tournaments/test.html create mode 100644 tournaments/migrations/0016_rename_initial_position_teamregistration_bracket_position.py create mode 100644 tournaments/migrations/0017_alter_match_court.py create mode 100644 tournaments/static/tournaments/test.html diff --git a/static/tournaments/css/style.css b/static/tournaments/css/style.css index e6bf2ae..9d6ea96 100644 --- a/static/tournaments/css/style.css +++ b/static/tournaments/css/style.css @@ -1,16 +1,16 @@ @font-face { font-family: "Montserrat-Regular"; - src: url("fonts/Montserrat/Montserrat-Regular.ttf") format("truetype"); + src: url("../fonts/Montserrat/Montserrat-Regular.ttf") format("truetype"); } @font-face { font-family: "Montserrat-SemiBold"; - src: url("fonts/Montserrat/Montserrat-SemiBold.ttf") format("truetype"); + src: url("../fonts/Montserrat/Montserrat-SemiBold.ttf") format("truetype"); } @font-face { font-family: "Anybody-ExtraBold"; - src: url("fonts/Anybody/Anybody-ExtraBold.ttf") format("truetype"); + src: url("../fonts/Anybody/Anybody-ExtraBold.ttf") format("truetype"); } html, @@ -250,13 +250,13 @@ tr { vertical-align: middle; } -.table-container { +/* .table-container { display: table; } .table-cell { display: table-cell; vertical-align: middle; -} +} */ .horizontal-padding { padding: 0px 20px; } @@ -419,3 +419,20 @@ tr { .w100px { width: 100px; } + +.table-row { + display: grid; + grid-template-columns: auto 1fr auto; + align-items: center; /* Vertically center the content within each column */ +} + +.table-cell { + flex-grow: 1; + text-align: center; + padding: 10px; +} + +.table-cell-large { + grid-column: 2 / span 1; /* Center column spans from column 2 to column 3 */ + text-align: left; +} diff --git a/static/tournaments/test.html b/static/tournaments/test.html new file mode 100644 index 0000000..1af9897 --- /dev/null +++ b/static/tournaments/test.html @@ -0,0 +1,164 @@ + + + + + + + + + + Padel + + + +
+
+
+
+
+
+ +
+

Bienvenue !

+

Matchs

+ +
+
+
+
+ +
+ + + + +
+
+ + + + + + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ Jacky Gun +
+ +
+ Joe Gun +
+ +
+
+ + 4 + + 6 + + 6 + +
+
+ +
+ +
+ +
+ + +
+ +
+ Jolly Jumper Gun +
+ +
+ Miky mike Miker +
+ +
+
+ + 6 + + 4 + + 2 + +
+
+ + +
+ +
+ + +
+
+ + + + + + +
+ +
+ + +
+ +
+ + + +
+ +
+ + +
+
+ + + + + +
+
+ + + + +
+ +
+
+ + + + diff --git a/tournaments/migrations/0016_rename_initial_position_teamregistration_bracket_position.py b/tournaments/migrations/0016_rename_initial_position_teamregistration_bracket_position.py new file mode 100644 index 0000000..a8a9b51 --- /dev/null +++ b/tournaments/migrations/0016_rename_initial_position_teamregistration_bracket_position.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-03-09 14:28 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0015_teamscore_delete_teamstate'), + ] + + operations = [ + migrations.RenameField( + model_name='teamregistration', + old_name='initial_position', + new_name='bracket_position', + ), + ] diff --git a/tournaments/migrations/0017_alter_match_court.py b/tournaments/migrations/0017_alter_match_court.py new file mode 100644 index 0000000..06a964b --- /dev/null +++ b/tournaments/migrations/0017_alter_match_court.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-03-09 16:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0016_rename_initial_position_teamregistration_bracket_position'), + ] + + operations = [ + migrations.AlterField( + model_name='match', + name='court', + field=models.CharField(blank=True, max_length=50, null=True), + ), + ] diff --git a/tournaments/models.py b/tournaments/models.py index 3a3d54c..8530149 100644 --- a/tournaments/models.py +++ b/tournaments/models.py @@ -151,13 +151,17 @@ class Tournament(models.Model): def live_matches(self): matches = [] - for group_stage in self.group_stage_set: - for match in group_stage.match_set: + for group_stage in self.groupstage_set.all(): + for match in group_stage.match_set.all(): matches.append(match) - for round in self.round_set: - for match in round.match_set: + for round in self.round_set.all(): + for match in round.match_set.all(): matches.append(match) + # matches = [m for m in matches if m.broadcasted==True] + + print(len(matches)) + return map(lambda match: match.live_match(), matches) # # Convert object attributes to a dictionary @@ -227,7 +231,7 @@ class Match(models.Model): end_date = models.DateTimeField(null=True, blank=True) index = models.IntegerField(null=True, blank=True) format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True) - court = models.IntegerField(null=True, blank=True) + court = models.CharField(max_length=50, null=True, blank=True) serving_team_id = models.UUIDField(null=True, blank=True) winning_team_id = models.UUIDField(null=True, blank=True) losing_team_id = models.UUIDField(null=True, blank=True) @@ -283,19 +287,20 @@ class Match(models.Model): # return (timezone.now() - self.start_date).total_seconds() def live_match(self): - title = f"{self.index}" + title = f"Match {self.index}" date = self.formatted_start_date() duration = self.formatted_duration() - - livematch = LiveMatch(title, date, duration) - - for team_state in self.team_scores: - - image = team_state.team_registration.logo - names = team_state.team_names() - scores = team_state.score - weight = team_state.team_registration.weight() - is_winner = team_state.team_registration == self.winning_team_id + court = "" + if self.court: + court = f"Terrain {self.court}" + livematch = LiveMatch(title, date, duration, court) + + for team_score in self.team_scores.all(): + image = team_score.team_registration.logo + names = team_score.team_names() + scores = team_score.scores_array() + weight = team_score.team_registration.weight() + is_winner = team_score.team_registration == self.winning_team_id team = Team(image, names, scores, weight, is_winner) livematch.add_team(team) @@ -307,7 +312,7 @@ class TeamRegistration(models.Model): group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.SET_NULL) registration_date = models.DateTimeField(null=True, blank=True) call_date = models.DateTimeField(null=True, blank=True) - initial_position = models.IntegerField(null=True, blank=True) + bracket_position = models.IntegerField(null=True, blank=True) group_stage_position = models.IntegerField(null=True, blank=True) comment = models.CharField(max_length=200, null=True, blank=True) source = models.CharField(max_length=20, null=True, blank=True) @@ -386,32 +391,34 @@ class TeamScore(models.Model): if self.team_registration.name: names.append(self.team_registration.name) else: - names = self.player_names() + names = list(map(lambda player: player.name(), self.player_registrations.all())) + return names + + def scores_array(self): + return [int(x) for x in self.score.split(',')] class Team: def __init__(self, image, names, scores, weight, is_winner): self.image = image - self.names = [] - self.scores = [] + self.names = names + self.scores = scores self.weight = weight self.is_winner = is_winner - def add_names(self, name): - self.names.append(name) - - def add_set_score(self, score): - self.scores.append(score) - class LiveMatch: - def __init__(self, title, date, duration): + def __init__(self, title, date, duration, court): self.title = title self.date = date self.teams = [] self.duration = duration + self.court = court def add_team(self, team): self.teams.append(team) + def toJSON(self): + return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4) + class TeamCall: def __init__(self, names, date, weight, stage, image): self.names = [] @@ -421,7 +428,6 @@ class TeamCall: self.stage = stage self.image = image - # class Set(models.Model): # class Game(models.Model): diff --git a/tournaments/serializers.py b/tournaments/serializers.py index d2ccb1c..0635247 100644 --- a/tournaments/serializers.py +++ b/tournaments/serializers.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from .models import Club, TeamScore, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamRegistration, PlayerRegistration +from .models import Club, LiveMatch, TeamScore, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamRegistration, PlayerRegistration from django.contrib.auth import password_validation from django.utils.translation import gettext_lazy as _ @@ -112,6 +112,11 @@ class ChangePasswordSerializer(serializers.Serializer): user.save() return user +class LiveMatchSerializer(serializers.ModelSerializer): + class Meta: + model = LiveMatch + fields = '__all__' # ['title', 'date'] # Serialize all fields of the model + # class ExpandedMatchSerializer(serializers.ModelSerializer): # team_states = TeamScoreSerializer(many=True, read_only=True) # class Meta: diff --git a/tournaments/static/tournaments/Padeltest.html b/tournaments/static/tournaments/Padeltest.html index 7326b66..461ef1e 100644 --- a/tournaments/static/tournaments/Padeltest.html +++ b/tournaments/static/tournaments/Padeltest.html @@ -1,10 +1,10 @@ - - + + - + Padel @@ -31,7 +31,7 @@ -->
diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index 6d21856..6df9919 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -217,14 +217,14 @@ tr { } .my-block { - padding: 0px 10px; + padding: 10px 10px; } -@media print, screen and (min-width: 40em) { +/* @media print, screen and (min-width: 40em) { .my-block { padding: 10px 10px; } -} +} */ .red { background-color: red; @@ -250,13 +250,13 @@ tr { vertical-align: middle; } -.table-container { +/* .table-container { display: table; } .table-cell { display: table-cell; vertical-align: middle; -} +} */ .horizontal-padding { padding: 0px 20px; } @@ -419,3 +419,21 @@ tr { .w100px { width: 100px; } + +.table-row { + display: grid; + grid-template-columns: auto 1fr auto; + align-items: center; /* Vertically center the content within each column */ + padding: 5px 0px; +} + +.table-cell { + flex-grow: 1; + text-align: center; + /* padding: 5px; */ +} + +.table-cell-large { + grid-column: 2 / span 1; /* Center column spans from column 2 to column 3 */ + text-align: left; +} diff --git a/tournaments/static/tournaments/test.html b/tournaments/static/tournaments/test.html new file mode 100644 index 0000000..1af9897 --- /dev/null +++ b/tournaments/static/tournaments/test.html @@ -0,0 +1,164 @@ + + + + + + + + + + Padel + + + +
+
+
+
+
+
+ +
+

Bienvenue !

+

Matchs

+ +
+
+
+
+ +
+ + + + +
+
+ + + + + + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ Jacky Gun +
+ +
+ Joe Gun +
+ +
+
+ + 4 + + 6 + + 6 + +
+
+ +
+ +
+ +
+ + +
+ +
+ Jolly Jumper Gun +
+ +
+ Miky mike Miker +
+ +
+
+ + 6 + + 4 + + 2 + +
+
+ + +
+ +
+ + +
+
+ + + + + + +
+ +
+ + +
+ +
+ + + +
+ +
+ + +
+
+ + + + + +
+
+ + + + +
+ +
+
+ +
+ + diff --git a/tournaments/templates/tournaments/base.html b/tournaments/templates/tournaments/base.html index 614ab23..8a463c8 100644 --- a/tournaments/templates/tournaments/base.html +++ b/tournaments/templates/tournaments/base.html @@ -23,6 +23,7 @@
+
@@ -38,14 +39,10 @@
- -
- {% block content %} - - {% endblock %} -
- -
+ + {% block content %} + + {% endblock %}
diff --git a/tournaments/templates/tournaments/match_cell.html b/tournaments/templates/tournaments/match_cell.html index 4b2db9e..c49ba9b 100644 --- a/tournaments/templates/tournaments/match_cell.html +++ b/tournaments/templates/tournaments/match_cell.html @@ -1,33 +1,46 @@ -
- -
- - -
- -
- - {% for team in match.teams %} -
-
- {% for name in team.names %} -
- {{ name }} -
- {% endfor %} -
-
- {% for score in team.scores %} - {{ score }} - {% endfor %} -
-
- {% endfor %} - -
- -
- - -
-
+{% load static %} + +
+
+ +
+ + +
+ +
+ + {% for team in match.teams %} + +
+ {% if team.image %} +
+ +
+ {% endif %} + +
+ {% for name in team.names %} +
+ {{ name }} +
+ {% endfor %} +
+
+ {% for score in team.scores %} + {{ score }} + {% endfor %} +
+
+ {% endfor %} + +
+ +
+ + + +
+ +
+
diff --git a/tournaments/templates/tournaments/matches.html b/tournaments/templates/tournaments/matches.html index 0756d25..7103545 100644 --- a/tournaments/templates/tournaments/matches.html +++ b/tournaments/templates/tournaments/matches.html @@ -4,23 +4,13 @@ {% block title %}Matchs{% endblock %} {% block content %} - -{% if matches %} - -
-
- {% if matches %} - - {% for match in matches %} - - {% include 'tournaments/match_cell.html' %} - - {% endfor %} - - {% endif %} -
-
- -{% endif %} - + {% if matches %} +
+ {% if matches %} + {% for match in matches %} + {% include 'tournaments/match_cell.html' %} + {% endfor %} + {% endif %} +
+ {% endif %} {% endblock %} diff --git a/tournaments/views.py b/tournaments/views.py index 5a7c9c0..ecacef0 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render, get_object_or_404 from django.http import HttpResponse -from .serializers import ClubSerializer, TournamentSerializer, UserSerializer, ChangePasswordSerializer, EventSerializer, RoundSerializer, GroupStageSerializer, MatchSerializer, TeamScoreSerializer, TeamRegistrationSerializer, PlayerRegistrationSerializer +from .serializers import ClubSerializer, TournamentSerializer, UserSerializer, ChangePasswordSerializer, EventSerializer, RoundSerializer, GroupStageSerializer, MatchSerializer, TeamScoreSerializer, TeamRegistrationSerializer, PlayerRegistrationSerializer, LiveMatchSerializer from .models import Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration from .models import TeamCall @@ -13,6 +13,7 @@ from rest_framework.generics import UpdateAPIView from django.template import loader from datetime import date from django.http import JsonResponse +import json def index(request): today = date.today() @@ -37,23 +38,33 @@ def index(request): content_type="text/html", ) - def tournament(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) - today = date.today() + live_matches = list(tournament.live_matches()) - 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') + template = loader.get_template('tournaments/matches.html') context = { - 'future': future_matches, - 'live': live_matches, - 'ended': ended_matches, + 'matches': live_matches, } return HttpResponse(template.render(context, 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)) + def tournament_planning(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) @@ -68,9 +79,9 @@ def tournament_planning(request, tournament_id): def tournament_json(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) - live_matches = tournament.live_matches() - return JsonResponse(live_matches.__dict__) - + live_matches = list(tournament.live_matches()) + data = json.dumps(live_matches, default=vars) + return HttpResponse(data, content_type='application/json') # def index(request): # club = Club.objects.first()