Adds publication boolean tests

clubs
Laurent 2 years ago
parent 0138dd29b2
commit 8631848acc
  1. 50
      tournaments/models/tournament.py
  2. 18
      tournaments/templates/tournaments/navigation_tournament.html

@ -260,6 +260,56 @@ class Tournament(models.Model):
matches.sort(key=lambda m: m.start_date, reverse=True)
return matches
def display_summons(self):
if self.end_date is not None:
return False
if self.publish_summons:
return True
if timezone.now().date() >= self.start_date.date():
return True
return False
def display_group_stages(self):
if len(self.groupstage_set.all()) == 0:
return False
if self.publish_group_stages:
return True
first_group_stage_start_date = self.group_stage_start_date()
if first_group_stage_start_date is None:
return False
elif timezone.now().date() >= first_group_stage_start_date.date():
return True
return False
def group_stage_start_date(self):
group_stages = [gs for gs in self.groupstage_set.all() if gs.start_date is not None]
return min(group_stages, key=lambda gs: gs.start_date).start_date
def display_matches(self):
bracket_matches = self.bracket_matches()
if len(bracket_matches) == 0:
return False
if self.publish_brackets:
return True
first_match_start_date = self.first_match_start_date(bracket_matches)
if first_match_start_date is None:
return False
elif timezone.now().date() >= first_match_start_date.date():
return True
return False
def bracket_matches(self):
matches = []
for round in self.round_set.all():
matches.extend(round.all_matches(False))
return matches
def first_match_start_date(self, bracket_matches):
matches = [m for m in bracket_matches if m.start_date is not None]
return min(matches, key=lambda m: m.start_date).start_date
class MatchGroup:
def __init__(self, name, matches):
self.name = name

@ -1,10 +1,14 @@
<nav class="margin10">
{% if tournament.display_matches %}
<a href="{% url 'tournament' tournament.id %}" class="mybox">Matches</a>
{% endif %}
<nav class="margin10">
<a href="{% url 'tournament' tournament.id %}" class="mybox">Matches</a>
<a href="{% url 'group-stages' tournament.id %}" class="mybox">Poules</a>
{% if tournament.display_group_stages %}
<a href="{% url 'group-stages' tournament.id %}" class="mybox">Poules</a>
{% endif %}
{% if tournament.in_progress %}
<a href="{% url 'tournament-summons' tournament.id %}" class="mybox">Convocations</a>
{% endif %}
{% if tournament.display_summons %}
<a href="{% url 'tournament-summons' tournament.id %}" class="mybox">Convocations</a>
{% endif %}
</nav>
</nav>

Loading…
Cancel
Save