Shows losing bracket results

clubs
Laurent 2 years ago
parent 7e9b370cca
commit 8d768ebc76
  1. 9
      tournaments/models/round.py
  2. 69
      tournaments/models/tournament.py
  3. 19
      tournaments/static/tournaments/css/style.css
  4. 19
      tournaments/templates/tournaments/matches.html
  5. 7
      tournaments/views.py

@ -6,10 +6,13 @@ class Round(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE)
index = models.IntegerField(default=0)
loser = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE)
loser = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE, related_name='children')
format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True)
def __str__(self):
if self.loser:
return f"{self.tournament.name} - Loser bracket of : {self.name()}"
else:
return f"{self.tournament.name} - {self.name()}"
# def stage_call(self):
@ -23,6 +26,10 @@ class Round(models.Model):
# return stage_call
def name(self):
if self.loser:
parent = self.loser.name()
return f"Matchs de classement [{parent}]"
else:
if self.index == 0:
return "Finale"
elif self.index == 1:

@ -70,46 +70,63 @@ class Tournament(models.Model):
summons.sort(key=lambda s: s.weight)
return summons
def live_matches(self, broadcasted, group_stage_id, round_id):
def match_groups(self, broadcasted, group_stage_id, round_id):
matches = []
match_groups = []
if group_stage_id:
matches = self.group_stage_matches(group_stage_id)
group_stage = self.groupstage_set.filter(id=group_stage_id).first()
match_groups.append(self.group_stage_match_group(group_stage, broadcasted))
elif round_id:
matches = self.round_matches(round_id)
round = self.round_set.filter(id=round_id).first()
match_groups = self.round_match_groups(round, broadcasted)
else:
matches = self.all_matches()
match_groups = self.all_groups(broadcasted)
# matches = [m for m in matches if m.broadcasted==True]
if not broadcasted:
matches = [m for m in matches if len(m.team_scores.all()) > 0]
return match_groups
matches.sort(key=lambda m: m.order)
return [match.live_match() for match in matches]
# return map(lambda match: match.live_match(), matches)
def all_matches(self):
matches = []
def all_groups(self, broadcasted):
groups = []
for group_stage in self.groupstage_set.all():
for match in group_stage.match_set.all():
matches.append(match)
group = self.group_stage_match_group(group_stage, broadcasted)
groups.append(group)
for round in self.round_set.all():
for match in round.match_set.all():
matches.append(match)
return matches
groups = self.round_match_groups(round, broadcasted)
return groups
def group_stage_matches(self, group_stage_id):
group_stage = self.groupstage_set.filter(id=group_stage_id).first()
return group_stage.match_set.all()
def group_stage_match_group(self, group_stage, broadcasted):
return self.create_match_group(group_stage.name(), group_stage.match_set.all(), broadcasted)
def round_matches(self, round_id):
round = self.round_set.filter(id=round_id).first()
return round.match_set.all()
def round_match_groups(self, round, broadcasted):
groups = []
group = self.create_match_group(round.name(), round.match_set.all(), broadcasted)
groups.append(group)
for child in round.children.all():
children_groups = self.round_match_groups(child, broadcasted)
groups.extend(children_groups)
return groups
def create_match_group(self, name, matches, broadcasted):
if not broadcasted:
matches = [m for m in matches if len(m.team_scores.all()) > 0]
matches.sort(key=lambda m: m.order)
live_matches = [match.live_match() for match in matches]
return MatchGroup(name, live_matches)
def live_group_stages(self):
return [gs.live_group_stages() for gs in self.groupstage_set.all()]
class MatchGroup:
def __init__(self, name, matches):
self.name = name
self.matches = matches
def add_match(self, match):
self.matches.append(match)
def add_matches(self, matches):
self.matches = matches
class TeamSummon:
def __init__(self, names, date, weight, stage, image):
self.names = names

@ -55,6 +55,16 @@ a:hover {
color: #f39200;
}
nav {
display: flex; /* Use flexbox */
flex-wrap: wrap; /* Allow items to wrap onto multiple lines */
justify-content: flex-start; /* Align items to the start */
}
nav a {
margin-right: 6px; /* Adjust the horizontal spacing between <a> elements */
}
/* a {
color: #707070;
padding: 8px 12px;
@ -374,6 +384,15 @@ tr {
.vertical-padding {
padding: 8px 0px;
}
.topmargin5 {
margin-top: 5px;
}
.topmargin10 {
margin-top: 10px;
}
.topmargin20 {
margin-top: 20px;
}
.tight {
line-height: 1.1;

@ -9,24 +9,31 @@
{% include 'tournaments/tournament_navigation.html' %}
{% if rounds or group_stages %}
<nav class="margin10 top-margin20">
<a href="{% url 'tournament' tournament.id %}" class="mybox">Tous les matchs</a>
<nav class="margin10">
<a href="{% url 'tournament' tournament.id %}" class="mybox topmargin5">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>
<a href="{% url 'tournament' tournament.id %}?group_stage={{ group_stage.id }}" class="mybox topmargin5">{{ group_stage.name }}</a>
{% endfor %}
{% for round in rounds %}
<a href="{% url 'tournament' tournament.id %}?round={{ round.id }}" class="mybox">{{ round.name }}</a>
<a href="{% url 'tournament' tournament.id %}?round={{ round.id }}" class="mybox topmargin5">{{ round.name }}</a>
{% endfor %}
</nav>
{% endif %}
{% if matches %}
{% for match_group in match_groups %}
{% if match_group.matches %}
<h1 class="club my-block topmargin20">{{ match_group.name }}</h1>
<div class="grid-x">
{% for match in matches %}
{% for match in match_group.matches %}
{% include 'tournaments/match_cell.html' %}
{% endfor %}
</div>
{% endif %}
{% endfor %}
{% endblock %}

@ -40,15 +40,18 @@ def tournament(request, tournament_id):
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))
match_groups = tournament.match_groups(False, group_stage_id, round_id)
rounds = tournament.round_set.filter(loser=None).order_by('-index')
group_stages = tournament.groupstage_set.order_by('index')
print(f"GROUPS = {len(match_groups)}")
return render(request, 'tournaments/matches.html', {
'tournament': tournament,
'rounds': rounds,
'group_stages': group_stages,
'matches': live_matches,
'match_groups': match_groups,
})
def tournament_summons(request, tournament_id):

Loading…
Cancel
Save