diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index 16a4d95..b1a6488 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -140,7 +140,7 @@ class GroupStage(models.Model): return False def is_completed(self): - return not self.match_set.filter(end_date__isnull=True).exists() + return not self.match_set.filter(end_date__isnull=True).exists() and self.match_set.count() > 0 class LiveGroupStage: def __init__(self, title, step, index): diff --git a/tournaments/models/match.py b/tournaments/models/match.py index 2c49b75..17d29a8 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -137,6 +137,9 @@ class Match(models.Model): team = Team(None, image, names, scores, weight, is_winner, walk_out) return team + def is_ready(self): + return self.team_scores.count() == 2 + def live_teams(self): #print('player names from match') ##return map(lambda ts: ts.player_names(), self.team_scores.all()) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 2abebf7..9d8ba06 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -900,7 +900,28 @@ class Tournament(models.Model): timezoned_datetime = timezone.localtime(self.start_date) end = timezoned_datetime + timedelta(days=self.day_duration + 1) now = timezone.now() - return now >= end and self.is_build_and_not_empty() + return now >= end and self.is_build_and_not_empty() and self.nearly_over() + + def nearly_over(self): + # First check group stages if they exist + if self.groupstage_set.count() > 0: + # Check if all group stages are completed + for group_stage in self.groupstage_set.all(): + if group_stage.is_completed(): + return True + + # If no group stages, check semi-finals + if self.round_set.count() > 0: + # Get round with index 1 (semi-finals) and no parent + semifinals = self.round_set.filter(index=1, parent=None).first() + if semifinals: + # Check if any match in semi-finals has started + for match in semifinals.match_set.all(): + if match.start_date is not None and match.is_ready(): + return True + return False + + return False def display_points_earned(self): return self.federal_level_category != FederalLevelCategory.UNLISTED and self.hide_points_earned is False