Fix round displayed too early

clubs
Laurent 1 year ago
parent 94cd2ce9c1
commit ac9d589f39
  1. 6
      tournaments/models/group_stage.py
  2. 26
      tournaments/models/tournament.py

@ -102,6 +102,12 @@ class GroupStage(models.Model):
else: else:
return False return False
def has_at_least_one_started_match(self):
for match in self.match_set.all():
if match.start_date:
return True
return False
class LiveGroupStage: class LiveGroupStage:
def __init__(self, title): def __init__(self, title):
self.title = title self.title = title

@ -358,7 +358,7 @@ class Tournament(models.Model):
matches = [m for m in matches if m.disabled is False] matches = [m for m in matches if m.disabled is False]
if matches: if matches:
return self.create_match_group(group_stage.display_name(), matches, broadcasted) return self.create_match_group(group_stage.display_name(), matches)
else: else:
return None return None
@ -372,7 +372,7 @@ class Tournament(models.Model):
matches = [m for m in matches if m.disabled is False] matches = [m for m in matches if m.disabled is False]
if matches: if matches:
group = self.create_match_group(round.name(), matches, broadcasted) group = self.create_match_group(round.name(), matches)
groups.append(group) groups.append(group)
ranking_matches = round.ranking_matches(hide_empty_matches) ranking_matches = round.ranking_matches(hide_empty_matches)
@ -382,12 +382,12 @@ class Tournament(models.Model):
ranking_matches = [m for m in ranking_matches if m.disabled is False] ranking_matches = [m for m in ranking_matches if m.disabled is False]
if len(ranking_matches) > 0: if len(ranking_matches) > 0:
group = self.create_match_group('Matchs de classement', ranking_matches, broadcasted) group = self.create_match_group('Matchs de classement', ranking_matches)
groups.append(group) groups.append(group)
return groups return groups
def create_match_group(self, name, matches, broadcasted): def create_match_group(self, name, matches):
matches = list(matches) matches = list(matches)
matches.sort(key=lambda m: m.index) matches.sort(key=lambda m: m.index)
live_matches = [match.live_match() for match in matches] live_matches = [match.live_match() for match in matches]
@ -436,7 +436,7 @@ class Tournament(models.Model):
group_stages = self.live_group_stages() group_stages = self.live_group_stages()
matches = self.broadcasted_group_stages_matches() matches = self.broadcasted_group_stages_matches()
first_round = self.first_round() first_round = self.first_round()
if first_round: if first_round and self.has_all_group_stages_started():
matches.extend(first_round.get_matches_recursive(True)) matches.extend(first_round.get_matches_recursive(True))
else: else:
current_round = self.round_to_show() current_round = self.round_to_show()
@ -596,16 +596,6 @@ class Tournament(models.Model):
else: else:
return timezone.now() >= first_group_stage_start_date return timezone.now() >= first_group_stage_start_date
# group_stage_start_date = self.getEightAm(first_group_stage_start_date)
# if group_stage_start_date < self.start_date:
# group_stage_start_date = self.start_date
# if datetime.now().date() >= group_stage_start_date.date():
# return True
# return False
def group_stage_start_date(self): def group_stage_start_date(self):
group_stages = [gs for gs in self.groupstage_set.all() if gs.start_date is not None] group_stages = [gs for gs in self.groupstage_set.all() if gs.start_date is not None]
if len(group_stages) == 0: if len(group_stages) == 0:
@ -673,6 +663,12 @@ class Tournament(models.Model):
else: else:
return False return False
def has_all_group_stages_started(self):
for group_stage in self.groupstage_set.all():
if group_stage.has_at_least_one_started_match() == False
return False
return True
class MatchGroup: class MatchGroup:
def __init__(self, name, matches): def __init__(self, name, matches):
self.name = name self.name = name

Loading…
Cancel
Save