display matches

clubs
Laurent 2 years ago
parent d704dc8c68
commit de3417b0d9
  1. 27
      static/tournaments/css/style.css
  2. 164
      static/tournaments/test.html
  3. 18
      tournaments/migrations/0016_rename_initial_position_teamregistration_bracket_position.py
  4. 18
      tournaments/migrations/0017_alter_match_court.py
  5. 62
      tournaments/models.py
  6. 7
      tournaments/serializers.py
  7. 8
      tournaments/static/tournaments/Padeltest.html
  8. 28
      tournaments/static/tournaments/css/style.css
  9. 164
      tournaments/static/tournaments/test.html
  10. 7
      tournaments/templates/tournaments/base.html
  11. 29
      tournaments/templates/tournaments/match_cell.html
  12. 16
      tournaments/templates/tournaments/matches.html
  13. 37
      tournaments/views.py

@ -1,16 +1,16 @@
@font-face { @font-face {
font-family: "Montserrat-Regular"; 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-face {
font-family: "Montserrat-SemiBold"; 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-face {
font-family: "Anybody-ExtraBold"; font-family: "Anybody-ExtraBold";
src: url("fonts/Anybody/Anybody-ExtraBold.ttf") format("truetype"); src: url("../fonts/Anybody/Anybody-ExtraBold.ttf") format("truetype");
} }
html, html,
@ -250,13 +250,13 @@ tr {
vertical-align: middle; vertical-align: middle;
} }
.table-container { /* .table-container {
display: table; display: table;
} }
.table-cell { .table-cell {
display: table-cell; display: table-cell;
vertical-align: middle; vertical-align: middle;
} } */
.horizontal-padding { .horizontal-padding {
padding: 0px 20px; padding: 0px 20px;
} }
@ -419,3 +419,20 @@ tr {
.w100px { .w100px {
width: 100px; 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;
}

@ -0,0 +1,164 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css/foundation.min.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<title>Padel</title>
</head>
<body>
<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="images/PadelClub_logo_512.png"
class="logo inline"
/>
<div class="inline">
<h1 class="club">Bienvenue !</h1>
<h1 class="event">Matchs</h1>
<!-- <span>Propulsé par Padel Club</span> -->
</div>
</div>
</div>
</div>
<main>
<div class="grid-x">
<div class="cell medium-3 large-3 topblock my-block">
<div class="bubble">
<div class="flex-row">
<label class="left-label matchtitle">Match 2</label>
<label class="right-label info"></label>
</div>
<div>
<div class="table-row bottom-border padding-bottom-small">
<div class="table-cell">
<img src="images/pc_icon_round_200.png" class="team_image" />
</div>
<div class="table-cell horizontal-padding table-cell table-cell-large">
<div class="">
Jacky Gun
</div>
<div class="">
Joe Gun
</div>
</div>
<div class="table-cell alignright">
<span class="score ws ">4</span>
<span class="score ws ">6</span>
<span class="score ws ">6</span>
</div>
</div>
<div class="table-row bottom-border padding-bottom-small">
<div class="table-cell">
<img src="images/pc_icon_round_200.png" class="team_image" />
</div>
<div class="table-cell horizontal-padding table-cell table-cell-large">
<div class="">
Jolly Jumper Gun
</div>
<div class="">
Miky mike Miker
</div>
</div>
<div class="table-cell alignright">
<span class="score ws ">6</span>
<span class="score ws ">4</span>
<span class="score ws ">2</span>
</div>
</div>
</div>
<div class="top-margin flex-row">
<label class="left-label minor-info">50h42min</label>
<!-- <a href="" class="right-label">détails</a> -->
</div>
</div>
<div class="bubble">
<div class="flex-row">
<label class="left-label matchtitle">Match 2</label>
<label class="right-label info"></label>
</div>
<div>
</div>
<div class="top-margin flex-row">
<label class="left-label minor-info">29h46min</label>
<!-- <a href="" class="right-label">détails</a> -->
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</main>
</div>
</body>
</html>

@ -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',
),
]

@ -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),
),
]

@ -151,13 +151,17 @@ class Tournament(models.Model):
def live_matches(self): def live_matches(self):
matches = [] matches = []
for group_stage in self.group_stage_set: for group_stage in self.groupstage_set.all():
for match in group_stage.match_set: for match in group_stage.match_set.all():
matches.append(match) matches.append(match)
for round in self.round_set: for round in self.round_set.all():
for match in round.match_set: for match in round.match_set.all():
matches.append(match) matches.append(match)
# matches = [m for m in matches if m.broadcasted==True]
print(len(matches))
return map(lambda match: match.live_match(), matches) return map(lambda match: match.live_match(), matches)
# # Convert object attributes to a dictionary # # Convert object attributes to a dictionary
@ -227,7 +231,7 @@ class Match(models.Model):
end_date = models.DateTimeField(null=True, blank=True) end_date = models.DateTimeField(null=True, blank=True)
index = models.IntegerField(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) 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) serving_team_id = models.UUIDField(null=True, blank=True)
winning_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) 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() # return (timezone.now() - self.start_date).total_seconds()
def live_match(self): def live_match(self):
title = f"{self.index}" title = f"Match {self.index}"
date = self.formatted_start_date() date = self.formatted_start_date()
duration = self.formatted_duration() duration = self.formatted_duration()
court = ""
livematch = LiveMatch(title, date, duration) if self.court:
court = f"Terrain {self.court}"
for team_state in self.team_scores: livematch = LiveMatch(title, date, duration, court)
image = team_state.team_registration.logo for team_score in self.team_scores.all():
names = team_state.team_names() image = team_score.team_registration.logo
scores = team_state.score names = team_score.team_names()
weight = team_state.team_registration.weight() scores = team_score.scores_array()
is_winner = team_state.team_registration == self.winning_team_id weight = team_score.team_registration.weight()
is_winner = team_score.team_registration == self.winning_team_id
team = Team(image, names, scores, weight, is_winner) team = Team(image, names, scores, weight, is_winner)
livematch.add_team(team) 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) group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.SET_NULL)
registration_date = models.DateTimeField(null=True, blank=True) registration_date = models.DateTimeField(null=True, blank=True)
call_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) group_stage_position = models.IntegerField(null=True, blank=True)
comment = models.CharField(max_length=200, null=True, blank=True) comment = models.CharField(max_length=200, null=True, blank=True)
source = models.CharField(max_length=20, 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: if self.team_registration.name:
names.append(self.team_registration.name) names.append(self.team_registration.name)
else: 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: class Team:
def __init__(self, image, names, scores, weight, is_winner): def __init__(self, image, names, scores, weight, is_winner):
self.image = image self.image = image
self.names = [] self.names = names
self.scores = [] self.scores = scores
self.weight = weight self.weight = weight
self.is_winner = is_winner 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: class LiveMatch:
def __init__(self, title, date, duration): def __init__(self, title, date, duration, court):
self.title = title self.title = title
self.date = date self.date = date
self.teams = [] self.teams = []
self.duration = duration self.duration = duration
self.court = court
def add_team(self, team): def add_team(self, team):
self.teams.append(team) self.teams.append(team)
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
class TeamCall: class TeamCall:
def __init__(self, names, date, weight, stage, image): def __init__(self, names, date, weight, stage, image):
self.names = [] self.names = []
@ -421,7 +428,6 @@ class TeamCall:
self.stage = stage self.stage = stage
self.image = image self.image = image
# class Set(models.Model): # class Set(models.Model):
# class Game(models.Model): # class Game(models.Model):

@ -1,5 +1,5 @@
from rest_framework import serializers 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.contrib.auth import password_validation
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -112,6 +112,11 @@ class ChangePasswordSerializer(serializers.Serializer):
user.save() user.save()
return user return user
class LiveMatchSerializer(serializers.ModelSerializer):
class Meta:
model = LiveMatch
fields = '__all__' # ['title', 'date'] # Serialize all fields of the model
# class ExpandedMatchSerializer(serializers.ModelSerializer): # class ExpandedMatchSerializer(serializers.ModelSerializer):
# team_states = TeamScoreSerializer(many=True, read_only=True) # team_states = TeamScoreSerializer(many=True, read_only=True)
# class Meta: # class Meta:

@ -1,10 +1,10 @@
<html> <html>
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="foundation.css" /> <link rel="stylesheet" href="css/foundation.css" />
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="css/style.css" />
<link rel="icon" type="image/png" href="favicon.png" /> <link rel="icon" type="image/png" href="images/favicon.png" />
<title>Padel</title> <title>Padel</title>
</head> </head>
@ -31,7 +31,7 @@
</div> --> </div> -->
<img <img
src="PadelClub_logo_512.png" src="images/PadelClub_logo_512.png"
class="logo inline" class="logo inline"
/> />
<div class="inline"> <div class="inline">

@ -217,14 +217,14 @@ tr {
} }
.my-block { .my-block {
padding: 0px 10px; padding: 10px 10px;
} }
@media print, screen and (min-width: 40em) { /* @media print, screen and (min-width: 40em) {
.my-block { .my-block {
padding: 10px 10px; padding: 10px 10px;
} }
} } */
.red { .red {
background-color: red; background-color: red;
@ -250,13 +250,13 @@ tr {
vertical-align: middle; vertical-align: middle;
} }
.table-container { /* .table-container {
display: table; display: table;
} }
.table-cell { .table-cell {
display: table-cell; display: table-cell;
vertical-align: middle; vertical-align: middle;
} } */
.horizontal-padding { .horizontal-padding {
padding: 0px 20px; padding: 0px 20px;
} }
@ -419,3 +419,21 @@ tr {
.w100px { .w100px {
width: 100px; 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;
}

@ -0,0 +1,164 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css/foundation.min.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<title>Padel</title>
</head>
<body>
<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="images/PadelClub_logo_512.png"
class="logo inline"
/>
<div class="inline">
<h1 class="club">Bienvenue !</h1>
<h1 class="event">Matchs</h1>
<!-- <span>Propulsé par Padel Club</span> -->
</div>
</div>
</div>
</div>
<main>
<div class="grid-x">
<div class="cell medium-3 large-3 topblock my-block">
<div class="bubble">
<div class="flex-row">
<label class="left-label matchtitle">Match 2</label>
<label class="right-label info"></label>
</div>
<div>
<div class="table-row bottom-border padding-bottom-small">
<div class="table-cell">
<img src="images/pc_icon_round_200.png" class="team_image" />
</div>
<div class="table-cell horizontal-padding table-cell table-cell-large">
<div class="">
Jacky Gun
</div>
<div class="">
Joe Gun
</div>
</div>
<div class="table-cell alignright">
<span class="score ws ">4</span>
<span class="score ws ">6</span>
<span class="score ws ">6</span>
</div>
</div>
<div class="table-row bottom-border padding-bottom-small">
<div class="table-cell">
<img src="images/pc_icon_round_200.png" class="team_image" />
</div>
<div class="table-cell horizontal-padding table-cell table-cell-large">
<div class="">
Jolly Jumper Gun
</div>
<div class="">
Miky mike Miker
</div>
</div>
<div class="table-cell alignright">
<span class="score ws ">6</span>
<span class="score ws ">4</span>
<span class="score ws ">2</span>
</div>
</div>
</div>
<div class="top-margin flex-row">
<label class="left-label minor-info">50h42min</label>
<!-- <a href="" class="right-label">détails</a> -->
</div>
</div>
<div class="bubble">
<div class="flex-row">
<label class="left-label matchtitle">Match 2</label>
<label class="right-label info"></label>
</div>
<div>
</div>
<div class="top-margin flex-row">
<label class="left-label minor-info">29h46min</label>
<!-- <a href="" class="right-label">détails</a> -->
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</main>
</div>
</body>
</html>

@ -23,6 +23,7 @@
<div class="wrapper"> <div class="wrapper">
<main class="page-body"> <main class="page-body">
<div class="container"> <div class="container">
<div class="grid-x"> <div class="grid-x">
<div class="cell medium-6 large-6 topblock my-block"> <div class="cell medium-6 large-6 topblock my-block">
<div class="bubble"> <div class="bubble">
@ -38,14 +39,10 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Content -->
<main>
{% block content %} {% block content %}
<!-- The content of child templates will be inserted here --> <!-- The content of child templates will be inserted here -->
{% endblock %} {% endblock %}
</main>
</div>
</div> </div>
</main> </main>
</div> </div>

@ -1,22 +1,32 @@
<div class="bubble"> {% load static %}
<div class="cell medium-6 large-3 my-block">
<div class="bubble">
<div class="flex-row"> <div class="flex-row">
<label class="left-label matchtitle">{{ match.title }}</label> <label class="left-label matchtitle">{{ match.title }}</label>
<label class="right-label info">{{ match.formatted_start_date }}</label> <label class="right-label info">{{ match.date }}</label>
</div> </div>
<div> <div>
{% for team in match.teams %} {% for team in match.teams %}
<div class="test bottom-border padding-bottom-small">
<div class="left-label"> <div class="table-row {% cycle 'bottom-border' '' %} padding-bottom-small">
{% if team.image %}
<div class="table-cell">
<img src="{% static 'tournaments/images/pc_icon_round_200.png' %}" class="team_image" />
</div>
{% endif %}
<div class="table-cell table-cell-large horizontal-padding">
{% for name in team.names %} {% for name in team.names %}
<div class="winner"> <div class="{% if team.is_winner %}winner{% endif %}">
{{ name }} {{ name }}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
<div class=""> <div class="table-cell alignright">
{% for score in team.scores %} {% for score in team.scores %}
<span class="score ws {% if team.is_winner %}winner{% endif %}">{{ score }}</span> <span class="score ws {% if team.is_winner %}winner{% endif %}">{{ score }}</span>
{% endfor %} {% endfor %}
@ -28,6 +38,9 @@
<div class="top-margin flex-row"> <div class="top-margin flex-row">
<label class="left-label minor-info">{{ match.duration }}</label> <label class="left-label minor-info">{{ match.duration }}</label>
<!-- <a href="" class="right-label">détails</a> --> <label class="right-label minor-info">{{ match.court }}</label>
<!-- <a href="" class="right-label">{{ match.court }}</a> -->
</div>
</div>
</div> </div>
</div>

@ -4,23 +4,13 @@
{% block title %}Matchs{% endblock %} {% block title %}Matchs{% endblock %}
{% block content %} {% block content %}
{% if matches %}
<div class="grid-x">
<div class="cell medium-6 large-6 topblock my-block">
{% if matches %} {% if matches %}
<div class="grid-x">
{% if matches %}
{% for match in matches %} {% for match in matches %}
{% include 'tournaments/match_cell.html' %} {% include 'tournaments/match_cell.html' %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</div> </div>
</div> {% endif %}
{% endif %}
{% endblock %} {% endblock %}

@ -1,6 +1,6 @@
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse 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 Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration
from .models import TeamCall from .models import TeamCall
@ -13,6 +13,7 @@ from rest_framework.generics import UpdateAPIView
from django.template import loader from django.template import loader
from datetime import date from datetime import date
from django.http import JsonResponse from django.http import JsonResponse
import json
def index(request): def index(request):
today = date.today() today = date.today()
@ -37,23 +38,33 @@ def index(request):
content_type="text/html", content_type="text/html",
) )
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() live_matches = list(tournament.live_matches())
future_matches = Match.objects.filter(end_date__isnull=True, start_date__gt=today).order_by('start_date') template = loader.get_template('tournaments/matches.html')
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 = { context = {
'future': future_matches, 'matches': live_matches,
'live': live_matches,
'ended': ended_matches,
} }
return HttpResponse(template.render(context, request)) 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): def tournament_planning(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=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): def tournament_json(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id) tournament = get_object_or_404(Tournament, pk=tournament_id)
live_matches = tournament.live_matches() live_matches = list(tournament.live_matches())
return JsonResponse(live_matches.__dict__) data = json.dumps(live_matches, default=vars)
return HttpResponse(data, content_type='application/json')
# def index(request): # def index(request):
# club = Club.objects.first() # club = Club.objects.first()

Loading…
Cancel
Save