Fix crashes

clubs
Laurent 2 years ago
parent 9bf00f605b
commit 0bb0bceca4
  1. 6
      tournaments/models/club.py
  2. 6
      tournaments/models/court.py
  3. 22
      tournaments/models/match.py
  4. 1
      tournaments/models/player_registration.py
  5. 2
      tournaments/models/tournament.py

@ -21,3 +21,9 @@ class Club(models.Model):
def events_count(self):
return len(self.event_set.all())
def court_name(self, index):
for court in self.court_set.all():
if court.index == index and court.name:
return court.name
return f"Terrain {index}"

@ -9,3 +9,9 @@ class Court(models.Model):
name = models.CharField(max_length=50, null=True, blank=True)
exit_allowed = models.BooleanField(default=False)
indoor = models.BooleanField(default=False)
def __str__(self):
if self.name:
return self.name
else:
return f"Terrain {self.index}"

@ -25,13 +25,14 @@ class Match(models.Model):
names = " / ".join(self.player_names())
return f"{self.stage_name()} #{self.index}: {names}"
# player_names = " / ".join(self.player_names())
# if self.round:
# return f"{match_name} > {player_names}"
# elif self.group_stage:
# return f"{match_name} > {player_names}"
# else:
# return "--"
def tournament(self):
if self.round:
return self.round.tournament
else:
return self.group_stage.tournament
def court_name(self, index):
return self.tournament().event.club.court_name(index)
def backup_name(self):
items = []
@ -109,16 +110,11 @@ class Match(models.Model):
_minutes = int((_seconds % 3600) / 60)
return f"{_hours:02d}h{_minutes:02d}min"
# def seconds(self):
# return (timezone.now() - self.start_date).total_seconds()
def live_match(self):
title = self.name if self.name else self.backup_name()
date = self.formatted_start_date()
duration = self.time_indication()
court = ""
if self.court:
court = f"Terrain {self.court}"
court = self.court_name(self.court_index)
ended = self.end_date is not None
livematch = LiveMatch(title, date, duration, court, self.started(), ended)

@ -34,7 +34,6 @@ class PlayerRegistration(models.Model):
source = models.IntegerField(choices=PlayerDataSource.choices, null=True, blank=True)
has_arrived = models.BooleanField(default=False)
def __str__(self):
return self.name()

@ -107,7 +107,7 @@ class Tournament(models.Model):
matches = [m for m in matches if m.should_appear()]
if matches:
return self.create_match_group(group_stage.name(), matches, broadcasted)
return self.create_match_group(group_stage.display_name(), matches, broadcasted)
else:
return None

Loading…
Cancel
Save