add new teams page

clubs
Razmig Sarkissian 2 years ago
parent 0ccbeff446
commit 96362c2b5c
  1. 2
      tournaments/models/group_stage.py
  2. 2
      tournaments/models/match.py
  3. 15
      tournaments/models/team_registration.py
  4. 48
      tournaments/models/tournament.py
  5. 4
      tournaments/templates/tournaments/navigation_tournament.html
  6. 13
      tournaments/templates/tournaments/team_row.html
  7. 35
      tournaments/templates/tournaments/teams.html
  8. 1
      tournaments/urls.py
  9. 10
      tournaments/views.py

@ -137,7 +137,7 @@ class GroupStageTeam:
self.wins = 0 self.wins = 0
self.losses = 0 self.losses = 0
self.diff = 0 self.diff = 0
self.weight = team_registration.get_weight() self.weight = team_registration.weight
def wins_losses(self): def wins_losses(self):
return f"{self.wins}/{self.losses}" return f"{self.wins}/{self.losses}"

@ -123,7 +123,7 @@ class Match(models.Model):
image = team_score.team_registration.logo image = team_score.team_registration.logo
names = team_score.team_names() names = team_score.team_names()
scores = team_score.scores_array() scores = team_score.scores_array()
weight = team_score.team_registration.get_weight() weight = team_score.team_registration.weight
is_winner = team_score.team_registration.id == self.winning_team_id is_winner = team_score.team_registration.id == self.winning_team_id
walk_out = team_score.walk_out walk_out = team_score.walk_out
team = Team(image, names, scores, weight, is_winner, walk_out) team = Team(image, names, scores, weight, is_winner, walk_out)

@ -70,10 +70,6 @@ class TeamRegistration(models.Model):
return self.group_stage.name() return self.group_stage.name()
else: else:
return "--" return "--"
def get_weight(self):
top_two_players = self.playerregistration_set.all().order_by('rank')[:2]
weight = 0
for player in top_two_players: for player in top_two_players:
rank = player.rank if player.rank is not None else 0 rank = player.rank if player.rank is not None else 0
weight += rank weight += rank
@ -81,3 +77,14 @@ class TeamRegistration(models.Model):
def is_valid_for_summon(self): def is_valid_for_summon(self):
return len(self.playerregistration_set.all()) > 0 return len(self.playerregistration_set.all()) > 0
def is_valid_for_display(self):
return len(self.playerregistration_set.all()) > 0 and self.walk_out is False
def base_start_stage(self):
if self.group_stage_position is not None:
return "Poule"
if self.bracket_position is not None:
return "Tableau"
return "Attente"

@ -75,13 +75,26 @@ class Tournament(models.Model):
if next_match: if next_match:
names = team_registration.team_names() names = team_registration.team_names()
stage = next_match.stage_name() stage = next_match.stage_name()
weight = team_registration.get_weight() weight = team_registration.weight
summon = TeamSummon(names, next_match.start_date, weight, stage, team_registration.logo) summon = TeamSummon(names, next_match.start_date, weight, stage, team_registration.logo)
summons.append(summon) summons.append(summon)
summons.sort(key=lambda s: s.weight) summons.sort(key=lambda s: s.weight)
return summons return summons
def teams(self):
teams = []
for team_registration in self.teamregistration_set.all():
if team_registration.is_valid_for_display():
names = team_registration.team_names()
weight = team_registration.weight
stage = team_registration.base_start_stage()
team = Team(names, weight, stage, team_registration.logo)
teams.append(team)
teams.sort(key=lambda s: s.weight)
return teams
def match_groups(self, broadcasted, group_stage_id, round_id): def match_groups(self, broadcasted, group_stage_id, round_id):
match_groups = [] match_groups = []
@ -153,7 +166,8 @@ class Tournament(models.Model):
group_stages_dicts = [gs.to_dict() for gs in group_stages] group_stages_dicts = [gs.to_dict() for gs in group_stages]
# if now is before the first match, we want to show the summons + group stage or first matches # if now is before the first match, we want to show the summons + group stage or first matches
if timezone.now() < self.start_date: # change timezone to datetime to avoid the bug RuntimeWarning: DateTimeField Tournament.start_date received a naive datetime (2024-05-16 00:00:00) while time zone support is active.
if datetime.now().date() < self.start_date.date():
team_summons_dicts = [summon.to_dict() for summon in self.team_summons()] team_summons_dicts = [summon.to_dict() for summon in self.team_summons()]
if group_stages: if group_stages:
return { return {
@ -261,6 +275,15 @@ class Tournament(models.Model):
matches.sort(key=lambda m: m.start_date, reverse=True) matches.sort(key=lambda m: m.start_date, reverse=True)
return matches return matches
def display_teams(self):
if self.end_date is not None:
return True
if self.publish_teams:
return True
if datetime.now().date() >= self.start_date.date():
return True
return False
def display_summons(self): def display_summons(self):
if self.end_date is not None: if self.end_date is not None:
return False return False
@ -292,6 +315,9 @@ class Tournament(models.Model):
def group_stage_start_date(self): def group_stage_start_date(self):
group_stages = [gs for gs in self.groupstage_set.all() if gs.start_date is not None] group_stages = [gs for gs in self.groupstage_set.all() if gs.start_date is not None]
if len(group_stages) == 0:
return None
return min(group_stages, key=lambda gs: gs.start_date).start_date return min(group_stages, key=lambda gs: gs.start_date).start_date
def display_matches(self): def display_matches(self):
@ -322,6 +348,9 @@ class Tournament(models.Model):
def first_match_start_date(self, bracket_matches): def first_match_start_date(self, bracket_matches):
matches = [m for m in bracket_matches if m.start_date is not None] matches = [m for m in bracket_matches if m.start_date is not None]
if len(matches) == 0:
return None
return min(matches, key=lambda m: m.start_date).start_date return min(matches, key=lambda m: m.start_date).start_date
def getEightAm(self, date): def getEightAm(self, date):
@ -361,3 +390,18 @@ class TeamSummon:
"stage": self.stage, "stage": self.stage,
"image": self.image, "image": self.image,
} }
class Team:
def __init__(self, names, weight, stage, image):
self.names = names
self.weight = weight
self.stage = stage
self.image = image
def to_dict(self):
return {
"names": self.names,
"weight": self.weight,
"stage": self.stage,
"image": self.image,
}

@ -11,4 +11,8 @@
<a href="{% url 'tournament-summons' tournament.id %}" class="mybox">Convocations</a> <a href="{% url 'tournament-summons' tournament.id %}" class="mybox">Convocations</a>
{% endif %} {% endif %}
{% if tournament.display_teams %}
<a href="{% url 'tournament-teams' tournament.id %}" class="mybox">Équipes</a>
{% endif %}
</nav> </nav>

@ -0,0 +1,13 @@
{% load static %}
<div class="table-row-4-colums bottom-border">
<div class="table-cell table-cell-large semibold">
{% for name in team.names %}
<div>{{ name }}</div>
{% endfor %}
</div>
<div class="table-cell center">{{ team.weight }}</div>
<div class="table-cell"><div class="mybox center">{{ team.stage }}</div></div>
</div>

@ -0,0 +1,35 @@
{% extends 'tournaments/base.html' %}
{% block head_title %}Équipes{% endblock %}
{% block first_title %}{{ tournament.display_name }}{% endblock %}
{% block second_title %}Équipes{% endblock %}
{% if tournament.display_teams %}
{% block content %}
{% load static %}
{% include 'tournaments/navigation_tournament.html' %}
{% if teams %}
<div class="grid-x padding-bottom">
<div class="cell medium-6 large-6 my-block">
<div class="bubble">
{% for team in teams %}
{% include 'tournaments/team_row.html' %}
{% endfor %}
</div>
</div>
</div>
{% endif %}
{% endblock %}
{% endif %}

@ -9,6 +9,7 @@ urlpatterns = [
path("tournament/<str:tournament_id>/", path("tournament/<str:tournament_id>/",
include([ include([
path('', views.tournament, name='tournament'), path('', views.tournament, name='tournament'),
path('teams/', views.tournament_teams, name='tournament-teams'),
path('summons/', views.tournament_summons, name='tournament-summons'), path('summons/', views.tournament_summons, name='tournament-summons'),
path('broadcast/summons/', views.tournament_broadcasted_summons, name='broadcasted-summons'), path('broadcast/summons/', views.tournament_broadcasted_summons, name='broadcasted-summons'),
path('summons/json/', views.tournament_summons_json, name='tournament-summons-json'), path('summons/json/', views.tournament_summons_json, name='tournament-summons-json'),

@ -97,6 +97,16 @@ def tournament(request, tournament_id):
'match_groups': match_groups, 'match_groups': match_groups,
}) })
def tournament_teams(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id)
teams = tournament.teams()
return render(request, 'tournaments/teams.html', {
'tournament': tournament,
'teams': teams,
})
def tournament_summons(request, tournament_id): def tournament_summons(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id) tournament = get_object_or_404(Tournament, pk=tournament_id)

Loading…
Cancel
Save