Fixes crash when match has no date

clubs
Laurent 1 year ago
parent fe50eed062
commit 0b46809116
  1. 7
      tournaments/models/match.py
  2. 7
      tournaments/models/tournament.py

@ -2,6 +2,7 @@ from django.db import models
from tournaments.models import group_stage from tournaments.models import group_stage
from . import Round, GroupStage, FederalMatchCategory from . import Round, GroupStage, FederalMatchCategory
from django.utils import timezone, formats from django.utils import timezone, formats
from datetime import timedelta
import uuid import uuid
class Match(models.Model): class Match(models.Model):
@ -165,6 +166,12 @@ class Match(models.Model):
else: else:
return self.team_scores.order_by('team_registration__bracket_position') 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): # def sort_value(self):
# sort_score = 0 # sort_score = 0
# if self.round.index: # if self.round.index:

@ -337,8 +337,6 @@ class Tournament(models.Model):
def create_match_group(self, name, matches, broadcasted): def create_match_group(self, name, matches, broadcasted):
matches = list(matches) matches = list(matches)
# if not broadcasted:
# matches = [m for m in matches if m.should_appear()]
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]
return MatchGroup(name, live_matches) return MatchGroup(name, live_matches)
@ -452,15 +450,14 @@ class Tournament(models.Model):
return matches[0] return matches[0]
def round_for_index(self, index): 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): def group_stages_matches(self):
matches = [] matches = []
for group_stage in self.groupstage_set.all(): for group_stage in self.groupstage_set.all():
matches.extend(group_stage.match_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.should_appear()]
# matches = [m for m in matches if m.start_date] matches.sort(key=lambda m: (m.non_null_start_date(), m.index), reverse=True)
matches.sort(key=lambda m: m.start_date, reverse=True)
return matches return matches
def display_rankings(self): def display_rankings(self):

Loading…
Cancel
Save