diff --git a/tournaments/models/event.py b/tournaments/models/event.py index dcd0838..03eb76d 100644 --- a/tournaments/models/event.py +++ b/tournaments/models/event.py @@ -16,3 +16,9 @@ class Event(models.Model): def __str__(self): return self.name + + def display_name(self): + if self.name: + return self.name + else: + return self.club.name diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index f2b44b3..167914b 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -21,3 +21,30 @@ class GroupStage(models.Model): def matches_for_registration(self, player_registration): team_scores = TeamScore.objects.filter(player_registrations=player_registration) return map(lambda ts: ts.match, team_scores) + + def live_group_stage(self): + lgs = LiveGroupStage(self.name()) + for team_registration in self.teamregistration_set.all(): + team = GroupStageTeam(team_registration.team_names(), self.score(), self.diff()) + lgs.add_team(team) + return lgs + + def score(self): + return "2-0" + + def diff(self): + return "+6" + +class LiveGroupStage: + def __init__(self, title): + self.title = title + self.teams = [] + + def add_team(self, team): + self.teams.append(team) + +class GroupStageTeam: + def __init__(self, names, score, diff): + self.names = names + self.score = score + self.diff = diff diff --git a/tournaments/models/match.py b/tournaments/models/match.py index e3b8f94..515b8bd 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -52,6 +52,9 @@ class Match(models.Model): else: return (timezone.now() - self.start_date).total_seconds() + def started(self): + return timezone.now() > self.start_date + def durationPrefix(self): if self.current_duration() > 0: return "Temps de jeu" @@ -82,7 +85,8 @@ class Match(models.Model): court = "" if self.court: court = f"Terrain {self.court}" - livematch = LiveMatch(title, date, duration, court) + + livematch = LiveMatch(title, date, duration, court, self.started()) for team_score in self.team_scores.all(): image = team_score.team_registration.logo @@ -104,15 +108,13 @@ class Team: self.is_winner = is_winner class LiveMatch: - def __init__(self, title, date, duration, court): + def __init__(self, title, date, duration, court, started): self.title = title self.date = date self.teams = [] self.duration = duration self.court = court + self.started = started def add_team(self, team): self.teams.append(team) - - # def toJSON(self): - # return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4) diff --git a/tournaments/models/team_score.py b/tournaments/models/team_score.py index f149b50..519f39d 100644 --- a/tournaments/models/team_score.py +++ b/tournaments/models/team_score.py @@ -27,4 +27,7 @@ class TeamScore(models.Model): return names def scores_array(self): - return [int(x) for x in self.score.split(',')] + if self.score: + return [int(x) for x in self.score.split(',')] + else: + return [] diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 625a642..3b2e974 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -74,6 +74,9 @@ class Tournament(models.Model): return map(lambda match: match.live_match(), matches) + def live_group_stages(self): + return map(lambda gs: gs.live_group_stage(), self.groupstage_set.all()) + class TeamSummon: def __init__(self, names, date, weight, stage, image): self.names = [] diff --git a/tournaments/static/tournaments/css/broadcast.css b/tournaments/static/tournaments/css/broadcast.css index 3c52c41..f5fd40a 100644 --- a/tournaments/static/tournaments/css/broadcast.css +++ b/tournaments/static/tournaments/css/broadcast.css @@ -14,5 +14,6 @@ body { padding: 20px; background-color: white; border-radius: 24px; - /* box-shadow: 10px 10px lightblue; */ + /* box-shadow: 0 0 0px 1px #fbead6; */ + box-shadow: 0 0 0px 0px #fbead6; } diff --git a/tournaments/templates/tournaments/base.html b/tournaments/templates/tournaments/base.html index fbcde98..d3c502e 100644 --- a/tournaments/templates/tournaments/base.html +++ b/tournaments/templates/tournaments/base.html @@ -27,17 +27,17 @@
-
+
-

Bienvenue !

-

{% block title %}Page Title{% endblock %}

+

{% block first_title %}Page Title{% endblock %}

+

{% block second_title %}Page Title{% endblock %}

-
+
diff --git a/tournaments/templates/tournaments/broadcasted_group_stages.html b/tournaments/templates/tournaments/broadcasted_group_stages.html new file mode 100644 index 0000000..e69de29 diff --git a/tournaments/templates/tournaments/match_cell.html b/tournaments/templates/tournaments/match_cell.html index 4516f3c..3454d57 100644 --- a/tournaments/templates/tournaments/match_cell.html +++ b/tournaments/templates/tournaments/match_cell.html @@ -27,9 +27,15 @@ {% endfor %}
- {% for score in team.scores %} - {{ score }} - {% endfor %} + + {% if match.started %} + {% for score in team.scores %} + {{ score }} + {% endfor %} + {% else %} + {{ team.weight }} + {% endif %} +
{% endfor %} diff --git a/tournaments/templates/tournaments/matches.html b/tournaments/templates/tournaments/matches.html index 20bd5d7..26a0053 100644 --- a/tournaments/templates/tournaments/matches.html +++ b/tournaments/templates/tournaments/matches.html @@ -1,7 +1,8 @@ {% extends 'tournaments/base.html' %} {% block head_title %}Matchs{% endblock %} -{% block title %}Matchs{% endblock %} +{% block first_title %}{{ tournament.event.display_name }}{% endblock %} +{% block second_title %}{{ tournament.name }}{% endblock %} {% block content %} {% if matches %} diff --git a/tournaments/templates/tournaments/summons.html b/tournaments/templates/tournaments/summons.html index 0116e48..101949a 100644 --- a/tournaments/templates/tournaments/summons.html +++ b/tournaments/templates/tournaments/summons.html @@ -1,45 +1,14 @@ - - {% load static %} +{% extends 'tournaments/base.html' %} - - - - +{% block head_title %}Matchs{% endblock %} +{% block first_title %}{{ tournament.name }}{% endblock %} +{% block second_title %}Convocations{% endblock %} - +{% block content %} - Padel Club - Convocations - - - - -
-
-
-
-
-
- -
-

4Padel Toulouse

-

Convocations

- -
-
-
-
+{% load static %} -
+
@@ -66,116 +35,55 @@
-
-
-
--> - +
+ - + --> diff --git a/tournaments/templates/tournaments/tournaments.html b/tournaments/templates/tournaments/tournaments.html index 5371fe2..79a1676 100644 --- a/tournaments/templates/tournaments/tournaments.html +++ b/tournaments/templates/tournaments/tournaments.html @@ -1,7 +1,8 @@ {% extends 'tournaments/base.html' %} {% block head_title %}Tournois{% endblock %} -{% block title %}Tournois{% endblock %} +{% block first_title %}Padel Club{% endblock %} +{% block second_title %}Tournois{% endblock %} {% block content %} diff --git a/tournaments/urls.py b/tournaments/urls.py index 9e2eb75..42da05f 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -8,5 +8,6 @@ urlpatterns = [ path('tournament//summons/', views.tournament_summons, name='tournament-summons'), path('tournament//broadcast/', views.tournament_matches, name='tournament-matches'), path('tournament//matches-json/', views.tournament_matches_json, name='tournament-matches-json'), + path('tournament//live-group-stages-json/', views.tournament_live_group_stage_json, name='live-group-stages-json'), path('players/', views.players, name='players'), ] diff --git a/tournaments/views.py b/tournaments/views.py index 0db06a3..34e9f4c 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -36,6 +36,7 @@ def tournament(request, tournament_id): live_matches = list(tournament.live_matches()) return render(request, 'tournaments/matches.html', { + 'tournament': tournament, 'matches': live_matches, }) @@ -45,22 +46,35 @@ def tournament_summons(request, tournament_id): team_summons = tournament.team_summons() return render(request, 'tournaments/summons.html', { + 'tournament': tournament, 'team_summons': team_summons, }) +def tournament_matches(request, tournament_id): + tournament = get_object_or_404(Tournament, pk=tournament_id) + return render(request, 'tournaments/broadcasted_matches.html', { + 'tournament': tournament, + }) + def tournament_matches_json(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) live_matches = list(tournament.live_matches()) data = json.dumps(live_matches, default=vars) return HttpResponse(data, content_type='application/json') -def tournament_matches(request, tournament_id): +def tournament_live_group_stage(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) - return render(request, 'tournaments/broadcasted_matches.html', { + return render(request, 'tournaments/broadcasted_group_stages.html', { 'tournament': tournament, }) +def tournament_live_group_stage_json(request, tournament_id): + tournament = get_object_or_404(Tournament, pk=tournament_id) + live_group_stages = list(tournament.live_group_stages()) + data = json.dumps(live_group_stages, default=vars) + return HttpResponse(data, content_type='application/json') + def players(request): return render(request, 'tournaments/test.html')