Fixes match order and summon date

clubs
Laurent 2 years ago
parent c432dc9d5a
commit 080e31d543
  1. 14
      tournaments/models/tournament.py

@ -109,7 +109,7 @@ class Tournament(models.Model):
def round_match_groups(self, round, broadcasted, hide_empty_matches): def round_match_groups(self, round, broadcasted, hide_empty_matches):
groups = [] groups = []
matches = round.match_set.all() matches = round.match_set.order_by('index').all()
if hide_empty_matches: if hide_empty_matches:
matches = [m for m in matches if m.should_appear()] matches = [m for m in matches if m.should_appear()]
@ -128,7 +128,7 @@ class Tournament(models.Model):
matches = list(matches) matches = list(matches)
# if not broadcasted: # if not broadcasted:
# matches = [m for m in matches if m.should_appear()] # matches = [m for m in matches if m.should_appear()]
matches.sort(key=lambda m: m.order) 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)
@ -175,7 +175,7 @@ class Tournament(models.Model):
matches = [] matches = []
group_stages = [] group_stages = []
last_started_match = self.last_started_match() last_started_match = self.first_unfinished_match()
current_round = last_started_match.round current_round = last_started_match.round
if current_round: if current_round:
@ -199,6 +199,11 @@ class Tournament(models.Model):
matches.extend(group_stage.match_set.all()) matches.extend(group_stage.match_set.all())
return matches return matches
def first_unfinished_match(self):
matches = [m for m in self.all_matches() if m.start_date and m.end_date is None]
matches.sort(key=lambda m: m.start_date)
return matches[0]
def last_started_match(self): def last_started_match(self):
matches = [m for m in self.all_matches() if m.start_date] matches = [m for m in self.all_matches() if m.start_date]
matches.sort(key=lambda m: m.start_date, reverse=True) matches.sort(key=lambda m: m.start_date, reverse=True)
@ -235,8 +240,11 @@ class TeamSummon:
self.image = image self.image = image
def formatted_date(self): def formatted_date(self):
if self.date:
timezoned_datetime = timezone.localtime(self.date) timezoned_datetime = timezone.localtime(self.date)
return formats.date_format(timezoned_datetime, format='H:i') return formats.date_format(timezoned_datetime, format='H:i')
else:
return None
def to_dict(self): def to_dict(self):
return { return {

Loading…
Cancel
Save