bracket-feature
laurent 11 months ago
commit d5d50d9eae
  1. 28
      tournaments/models/tournament.py

@ -685,19 +685,37 @@ class Tournament(models.Model):
print(f'round_to_show > current_round: {current_round.name()}') print(f'round_to_show > current_round: {current_round.name()}')
if current_round: if current_round:
return current_round return current_round
main_rounds = list(self.round_set.filter(parent=None).all())
main_rounds.sort(key=lambda r: r.index) # all started matches have ended, possibly
if main_rounds: last_finished_match = self.last_finished_match()
print(f'round_to_show > main_rounds: {main_rounds[0].name()}') round_index = last_finished_match.round.index
return main_rounds[0] if round_index == 0:
return last_finished_match.round
else:
round = self.round_set.filter(parent=None,index=round_index-1).first()
if round:
return round
else: else:
return None return None
# main_rounds = list(self.round_set.filter(parent=None).all())
# main_rounds.sort(key=lambda r: r.index)
# if main_rounds:
# print(f'round_to_show > main_rounds: {main_rounds[0].name()}')
# return main_rounds[0]
# else:
# return None
def last_started_match(self): def last_started_match(self):
matches = [m for m in self.all_matches(False) if m.start_date] matches = [m for m in self.all_matches(False) if m.start_date]
matches.sort(key=lambda m: m.start_date, reverse=True) matches.sort(key=lambda m: m.start_date, reverse=True)
return matches[0] if matches else None return matches[0] if matches else None
def last_finished_match(self):
matches = [m for m in self.all_matches(False) if m.end_date]
matches.sort(key=lambda m: m.end_date, reverse=True)
return matches[0] if matches else None
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()

Loading…
Cancel
Save