From 0b46809116e2acbf076445d7a40c192d2a05e77f Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 12 Jun 2024 14:55:00 +0200 Subject: [PATCH] Fixes crash when match has no date --- tournaments/models/match.py | 7 +++++++ tournaments/models/tournament.py | 7 ++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tournaments/models/match.py b/tournaments/models/match.py index 42d5909..fe93234 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -2,6 +2,7 @@ from django.db import models from tournaments.models import group_stage from . import Round, GroupStage, FederalMatchCategory from django.utils import timezone, formats +from datetime import timedelta import uuid class Match(models.Model): @@ -165,6 +166,12 @@ class Match(models.Model): else: return self.team_scores.order_by('team_registration__bracket_position') + def sort_start_date(self): + if self.start_date: + return self.start_date + else: + return timezone.now() + timedelta(days=7) + # def sort_value(self): # sort_score = 0 # if self.round.index: diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 9d42733..68c9509 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -337,8 +337,6 @@ class Tournament(models.Model): def create_match_group(self, name, matches, broadcasted): matches = list(matches) - # if not broadcasted: - # matches = [m for m in matches if m.should_appear()] matches.sort(key=lambda m: m.index) live_matches = [match.live_match() for match in matches] return MatchGroup(name, live_matches) @@ -452,15 +450,14 @@ class Tournament(models.Model): return matches[0] def round_for_index(self, index): - return self.round_set.filter(index=index,parent=None).first() + return self.round_set.filter(index=index, parent=None).first() def group_stages_matches(self): matches = [] for group_stage in self.groupstage_set.all(): matches.extend(group_stage.match_set.all()) matches = [m for m in matches if m.should_appear()] - # matches = [m for m in matches if m.start_date] - matches.sort(key=lambda m: m.start_date, reverse=True) + matches.sort(key=lambda m: (m.non_null_start_date(), m.index), reverse=True) return matches def display_rankings(self):