clubs
Laurent 2 years ago
parent c21e625418
commit 71b359e559
  1. 5
      padelclub_backend/settings.py
  2. 23
      tournaments/migrations/0020_alter_groupstage_index_alter_round_index.py
  3. 28
      tournaments/migrations/0021_match_name_match_order_and_more.py
  4. 6
      tournaments/models/enums.py
  5. 2
      tournaments/models/group_stage.py
  6. 34
      tournaments/models/match.py
  7. 2
      tournaments/models/round.py
  8. 2
      tournaments/models/tournament.py
  9. 2
      tournaments/templates/tournaments/match_cell.html
  10. 5
      tournaments/templates/tournaments/tournament_row.html

@ -109,6 +109,11 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGES = [
('fr', 'French'),
('en', 'English'),
]
LANGUAGE_CODE = 'fr' LANGUAGE_CODE = 'fr'
TIME_ZONE = 'CET' TIME_ZONE = 'CET'

@ -0,0 +1,23 @@
# Generated by Django 4.2.11 on 2024-03-13 08:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tournaments', '0019_alter_match_index'),
]
operations = [
migrations.AlterField(
model_name='groupstage',
name='index',
field=models.IntegerField(default=0),
),
migrations.AlterField(
model_name='round',
name='index',
field=models.IntegerField(default=0),
),
]

@ -0,0 +1,28 @@
# Generated by Django 4.2.11 on 2024-03-13 08:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tournaments', '0020_alter_groupstage_index_alter_round_index'),
]
operations = [
migrations.AddField(
model_name='match',
name='name',
field=models.CharField(blank=True, max_length=200, null=True),
),
migrations.AddField(
model_name='match',
name='order',
field=models.IntegerField(default=0),
),
migrations.AlterField(
model_name='tournament',
name='federal_category',
field=models.IntegerField(choices=[(0, 'Homme'), (1, 'Femme'), (2, 'Mixte')], default=0),
),
]

@ -2,9 +2,9 @@ from django.db import models
import uuid import uuid
class FederalCategory(models.IntegerChoices): class FederalCategory(models.IntegerChoices):
MEN = 0, 'Men' MEN = 0, 'Homme'
WOMEN = 1, 'Women' WOMEN = 1, 'Femme'
MIXED = 2, 'Mixed' MIXED = 2, 'Mixte'
class FederalLevelCategory(models.IntegerChoices): class FederalLevelCategory(models.IntegerChoices):
P25 = 25, 'P25' P25 = 25, 'P25'

@ -5,7 +5,7 @@ import uuid
class GroupStage(models.Model): class GroupStage(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE) tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE)
index = models.IntegerField(null=True, blank=True) index = models.IntegerField(default=0)
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)
def __str__(self): def __str__(self):

@ -2,14 +2,17 @@ from django.db import models
from . import Round, GroupStage, FederalMatchCategory from . import Round, GroupStage, FederalMatchCategory
from django.utils import timezone from django.utils import timezone
import uuid import uuid
from django.utils import formats
class Match(models.Model): class Match(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.CASCADE) round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.CASCADE)
name = models.CharField(max_length=200, null=True, blank=True)
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.CASCADE) group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.CASCADE)
start_date = models.DateTimeField(null=True, blank=True) start_date = models.DateTimeField(null=True, blank=True)
end_date = models.DateTimeField(null=True, blank=True) end_date = models.DateTimeField(null=True, blank=True)
index = models.IntegerField(default=0) index = models.IntegerField(default=0)
order = models.IntegerField(default=0)
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.CharField(max_length=50, 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)
@ -18,8 +21,8 @@ class Match(models.Model):
broadcasted = models.BooleanField(default=False) broadcasted = models.BooleanField(default=False)
def __str__(self): def __str__(self):
match_name = self.name if self.name else self.backup_name() #"x is greater" if x > y else "y is greater"
items = [self.name(), self.formatted_start_date()] items = [match_name, self.formatted_start_date()]
desc = " - ".join(items) desc = " - ".join(items)
player_names = " / ".join(self.player_names()) player_names = " / ".join(self.player_names())
if self.round: if self.round:
@ -29,7 +32,7 @@ class Match(models.Model):
else: else:
return "--" return "--"
def name(self): def backup_name(self):
items = [] items = []
if self.round: if self.round:
items.append(self.round.name()) items.append(self.round.name())
@ -64,15 +67,17 @@ class Match(models.Model):
if self.started(): if self.started():
return self.formatted_duration() return self.formatted_duration()
else: else:
start = self.start_date.strftime("%H:%M") return formats.date_format(self.start_date, format='SHORT_DATETIME_FORMAT')
return f"Prévu à {start}" # return self.start_date.strftime("%A %d %B à %H:%M")
# return f"Prévu à {start}"
else: else:
return 'À venir...' return 'À venir...'
def current_duration(self): def current_duration(self):
if self.start_date:
if self.end_date: if self.end_date:
return (self.end_date - self.start_date).total_seconds() return (self.end_date - self.start_date).total_seconds()
elif self.start_date: else:
return (timezone.now() - self.start_date).total_seconds() return (timezone.now() - self.start_date).total_seconds()
else: else:
return 0 return 0
@ -101,7 +106,7 @@ 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 = self.name() title = self.name
date = self.formatted_start_date() date = self.formatted_start_date()
duration = self.time_indication() duration = self.time_indication()
court = "" court = ""
@ -110,7 +115,7 @@ class Match(models.Model):
livematch = LiveMatch(title, date, duration, court, self.started()) livematch = LiveMatch(title, date, duration, court, self.started())
for team_score in self.team_scores.all(): for team_score in self.sorted_team_scores():
image = team_score.team_registration.logo image = team_score.team_registration.logo
names = team_score.team_names() names = team_score.team_names()
scores = team_score.scores_array() scores = team_score.scores_array()
@ -121,6 +126,19 @@ class Match(models.Model):
return livematch return livematch
def sorted_team_scores(self):
return self.team_scores.order_by('team_registration__bracket_position')
# def sort_value(self):
# sort_score = 0
# if self.round.index:
# sort_score += 1 / (self.round.index + 1) * 1000 ** 2
# if self.group_stage.index:
# sort_score += 1 / (self.group_stage.index + 1) * 1000
# sort_score += self.index
# print(sort_score)
# return sort_score
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

@ -5,7 +5,7 @@ import uuid
class Round(models.Model): class Round(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE) tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE)
index = models.IntegerField(null=True, blank=True) index = models.IntegerField(default=0)
loser = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE) loser = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE)
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)

@ -76,6 +76,8 @@ class Tournament(models.Model):
matches.append(match) matches.append(match)
matches = [m for m in matches if m.broadcasted==True] matches = [m for m in matches if m.broadcasted==True]
matches = [m for m in matches if len(m.team_scores.all()) > 0]
matches.sort(key=lambda m: m.order)
return map(lambda match: match.live_match(), matches) return map(lambda match: match.live_match(), matches)

@ -19,7 +19,7 @@
</div> </div>
{% endif %} --> {% endif %} -->
<div class="table-cell table-cell-large hpadding10"> <div class="table-cell table-cell-large">
{% for name in team.names %} {% for name in team.names %}
<div class="semibold {% if team.is_winner %}winner{% endif %}"> <div class="semibold {% if team.is_winner %}winner{% endif %}">
{{ name }} {{ name }}

@ -5,7 +5,10 @@
<div class="large">{{ tournament.level }}</div> <div class="large">{{ tournament.level }}</div>
<div class="small">{{ tournament.category }}</div> <div class="small">{{ tournament.category }}</div>
</div> </div>
<div class="table-cell table-cell-large horizontal-padding semibold">{{ tournament.event.club.name }}</div> <div class="table-cell table-cell-large horizontal-padding semibold">
<span>{{ tournament.event.club.name }}: </span>
<span>{{ tournament.name }}</span>
</div>
<div class="table-cell"><div class="mybox">{{ tournament.formatted_start_date }}</div></div> <div class="table-cell"><div class="mybox">{{ tournament.formatted_start_date }}</div></div>
</div> </div>
</a> </a>

Loading…
Cancel
Save