Add rounds in the matches navigtaion

clubs
Laurent 2 years ago
parent 10e0a5cceb
commit 26a5ecf2c9
  1. 2
      tournaments/models/match.py
  2. 38
      tournaments/models/tournament.py
  3. 4
      tournaments/templates/tournaments/base.html
  4. 13
      tournaments/templates/tournaments/matches.html
  5. 11
      tournaments/views.py

@ -6,8 +6,8 @@ import uuid
class Match(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.CASCADE)
name = models.CharField(max_length=200, null=True, blank=True)
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.CASCADE)
name = models.CharField(max_length=200, null=True, blank=True)
start_date = models.DateTimeField(null=True, blank=True)
end_date = models.DateTimeField(null=True, blank=True)
index = models.IntegerField(default=0)

@ -53,6 +53,9 @@ class Tournament(models.Model):
def formatted_start_date(self):
return self.start_date.strftime("%d/%m/%y")
def in_progress(self):
return self.end_date is None
def team_summons(self):
summons = []
for team_registration in self.teamregistration_set.all():
@ -67,14 +70,15 @@ class Tournament(models.Model):
summons.sort(key=lambda s: s.weight)
return summons
def live_matches(self, broadcasted):
def live_matches(self, broadcasted, group_stage_id, round_id):
matches = []
for group_stage in self.groupstage_set.all():
for match in group_stage.match_set.all():
matches.append(match)
for round in self.round_set.all():
for match in round.match_set.all():
matches.append(match)
if group_stage_id:
matches = self.group_stage_matches(group_stage_id)
elif round_id:
matches = self.round_matches(round_id)
else:
matches = self.all_matches()
matches = [m for m in matches if m.broadcasted==True]
if not broadcasted:
@ -85,6 +89,26 @@ class Tournament(models.Model):
return [match.live_match() for match in matches]
# return map(lambda match: match.live_match(), matches)
def all_matches(self):
matches = []
for group_stage in self.groupstage_set.all():
for match in group_stage.match_set.all():
matches.append(match)
for round in self.round_set.all():
for match in round.match_set.all():
matches.append(match)
return matches
def group_stage_matches(self, group_stage_id):
group_stage = self.groupstage_set.filter(id=group_stage_id).first()
print(group_stage.name())
print(len(group_stage.match_set.all()))
return group_stage.match_set.all()
def round_matches(self, round_id):
round = self.round_set.filter(id=round_id).first()
return round.match_set.all()
def live_group_stages(self):
return [gs.live_group_stages() for gs in self.groupstage_set.all()]
# return map(lambda gs: gs.live_group_stages(), self.groupstage_set.all())

@ -44,7 +44,11 @@
<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.in_progress %}
<a href="{% url 'tournament-summons' tournament.id %}" class="mybox">Convocations</a>
{% endif %}
</nav>
<main>

@ -6,7 +6,20 @@
{% block content %}
{% if rounds or group_stages %}
<nav class="margin10 top-margin20">
<a href="{% url 'tournament' tournament.id %}" class="mybox">Tous les matchs</a>
{% for group_stage in group_stages %}
<a href="{% url 'tournament' tournament.id %}?group_stage={{ group_stage.id }}" class="mybox">{{ group_stage.name }}</a>
{% endfor %}
{% for round in rounds %}
<a href="{% url 'tournament' tournament.id %}?round={{ round.id }}" class="mybox">{{ round.name }}</a>
{% endfor %}
</nav>
{% endif %}
{% if matches %}
<div class="grid-x">
{% for match in matches %}
{% include 'tournaments/match_cell.html' %}

@ -35,10 +35,19 @@ def index(request):
)
def tournament(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id)
live_matches = list(tournament.live_matches(broadcasted=False))
round_id = request.GET.get('round')
group_stage_id = request.GET.get('group_stage')
live_matches = list(tournament.live_matches(False, group_stage_id, round_id))
rounds = tournament.round_set.order_by('index')
group_stages = tournament.groupstage_set.order_by('index')
return render(request, 'tournaments/matches.html', {
'tournament': tournament,
'rounds': rounds,
'group_stages': group_stages,
'matches': live_matches,
})

Loading…
Cancel
Save