From 46c5cbfe494ef4c49e009410365e8711316584cf Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 11 Mar 2024 15:58:05 +0100 Subject: [PATCH] broadcast page with pagination and autorefresh! --- tournaments/models/match.py | 23 ++- tournaments/models/tournament.py | 7 - .../static/tournaments/css/broadcast.css | 18 +++ tournaments/static/tournaments/css/style.css | 15 +- .../static/tournaments/js/alpine.min.js | 5 + tournaments/templates/tournaments/base.html | 1 + .../tournaments/broadcasted_matches.html | 152 ++++++++++++++++++ .../templates/tournaments/matches.html | 2 - tournaments/templates/tournaments/test.html | 76 +++++---- tournaments/urls.py | 3 +- tournaments/views.py | 9 +- 11 files changed, 251 insertions(+), 60 deletions(-) create mode 100644 tournaments/static/tournaments/css/broadcast.css create mode 100644 tournaments/static/tournaments/js/alpine.min.js create mode 100644 tournaments/templates/tournaments/broadcasted_matches.html diff --git a/tournaments/models/match.py b/tournaments/models/match.py index bb1768e..e3b8f94 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -19,13 +19,22 @@ class Match(models.Model): def __str__(self): - items = [f"Match {self.index}", self.formatted_start_date()] + items = [self.name(), self.formatted_start_date()] desc = " - ".join(items) player_names = " / ".join(self.player_names()) if self.round: - return f"{str(self.round)} > {desc} > {player_names}" + return f"{desc} > {player_names}" elif self.group_stage: - return f"{str(self.group_stage)} > {desc} > {player_names}" + return f"{desc} > {player_names}" + + def name(self): + items = [] + if self.round: + items.append(self.round.name()) + elif self.group_stage: + items.append(self.group_stage.name()) + items.append(f"{self.index}") + return " ".join(items) def player_names(self): return map(lambda ts: ts.player_names(), self.team_scores.all()) @@ -67,7 +76,7 @@ class Match(models.Model): # return (timezone.now() - self.start_date).total_seconds() def live_match(self): - title = f"Match {self.index}" + title = self.name() date = self.formatted_start_date() duration = self.formatted_duration() court = "" @@ -80,7 +89,7 @@ class Match(models.Model): names = team_score.team_names() scores = team_score.scores_array() weight = team_score.team_registration.weight() - is_winner = team_score.team_registration == self.winning_team_id + is_winner = team_score.team_registration.id == self.winning_team_id team = Team(image, names, scores, weight, is_winner) livematch.add_team(team) @@ -105,5 +114,5 @@ class LiveMatch: 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) + # def toJSON(self): + # return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 40eb5ea..625a642 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -72,15 +72,8 @@ class Tournament(models.Model): # matches = [m for m in matches if m.broadcasted==True] - print(len(matches)) - return map(lambda match: match.live_match(), matches) - # # Convert object attributes to a dictionary - # dict = self.__dict__ - # # Convert dictionary to JSON - # return json.dumps(dict) - 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 new file mode 100644 index 0000000..3c52c41 --- /dev/null +++ b/tournaments/static/tournaments/css/broadcast.css @@ -0,0 +1,18 @@ +html, +body { + background: linear-gradient( + 20deg, + #1b223a 0 20%, + #e84038 20% 40%, + #f39200 40% 60%, + #ffd300 60% 80%, + #1b223a 80% 100% + ); +} + +.bubble { + padding: 20px; + background-color: white; + border-radius: 24px; + /* box-shadow: 10px 10px lightblue; */ +} diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index f1a53c3..6bbb5a0 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -15,14 +15,7 @@ html, body { - background: linear-gradient( - 20deg, - #1b223a 0 20%, - #e84038 20% 40%, - #f39200 40% 60%, - #ffd300 60% 80%, - #1b223a 80% 100% - ); + background: #fff7ed; font-family: "Montserrat-Regular"; font-size: 16px; @@ -34,8 +27,6 @@ body { height: 100%; padding: 0; margin: 0; - - overflow: hidden; } label { @@ -239,7 +230,7 @@ tr { padding: 20px; background-color: white; border-radius: 24px; - /* box-shadow: 10px 10px lightblue; */ + box-shadow: 0 0 10px 5px #fbead6; } .test { @@ -361,6 +352,8 @@ tr { .flex-row { display: flex; justify-content: space-between; + height: 29px; + align-items: center; /* vertical-align: middle; */ } diff --git a/tournaments/static/tournaments/js/alpine.min.js b/tournaments/static/tournaments/js/alpine.min.js new file mode 100644 index 0000000..f750e64 --- /dev/null +++ b/tournaments/static/tournaments/js/alpine.min.js @@ -0,0 +1,5 @@ +(()=>{var rt=!1,nt=!1,U=[],it=-1;function Vt(e){Sn(e)}function Sn(e){U.includes(e)||U.push(e),An()}function ve(e){let t=U.indexOf(e);t!==-1&&t>it&&U.splice(t,1)}function An(){!nt&&!rt&&(rt=!0,queueMicrotask(On))}function On(){rt=!1,nt=!0;for(let e=0;ee.effect(t,{scheduler:r=>{ot?Vt(r):r()}}),st=e.raw}function at(e){D=e}function Wt(e){let t=()=>{};return[n=>{let i=D(n);return e._x_effects||(e._x_effects=new Set,e._x_runEffects=()=>{e._x_effects.forEach(o=>o())}),e._x_effects.add(i),t=()=>{i!==void 0&&(e._x_effects.delete(i),L(i))},i},()=>{t()}]}function Se(e,t){let r=!0,n,i=D(()=>{let o=e();JSON.stringify(o),r?n=o:queueMicrotask(()=>{t(o,n),n=o}),r=!1});return()=>L(i)}function W(e,t,r={}){e.dispatchEvent(new CustomEvent(t,{detail:r,bubbles:!0,composed:!0,cancelable:!0}))}function C(e,t){if(typeof ShadowRoot=="function"&&e instanceof ShadowRoot){Array.from(e.children).forEach(i=>C(i,t));return}let r=!1;if(t(e,()=>r=!0),r)return;let n=e.firstElementChild;for(;n;)C(n,t,!1),n=n.nextElementSibling}function E(e,...t){console.warn(`Alpine Warning: ${e}`,...t)}var Gt=!1;function Jt(){Gt&&E("Alpine has already been initialized on this page. Calling Alpine.start() more than once can cause problems."),Gt=!0,document.body||E("Unable to initialize. Trying to load Alpine before `` is available. Did you forget to add `defer` in Alpine's ` + + + + + +
+
+
+ +
+
+
+ +
+

4Padel Toulouse

+

Matchs

+ +
+
+
+
+ +
+ + + +
+ +
+
+
+ + + diff --git a/tournaments/templates/tournaments/matches.html b/tournaments/templates/tournaments/matches.html index 7103545..20bd5d7 100644 --- a/tournaments/templates/tournaments/matches.html +++ b/tournaments/templates/tournaments/matches.html @@ -6,11 +6,9 @@ {% block content %} {% if matches %}
- {% if matches %} {% for match in matches %} {% include 'tournaments/match_cell.html' %} {% endfor %} - {% endif %}
{% endif %} {% endblock %} diff --git a/tournaments/templates/tournaments/test.html b/tournaments/templates/tournaments/test.html index faeebb9..cf4079b 100644 --- a/tournaments/templates/tournaments/test.html +++ b/tournaments/templates/tournaments/test.html @@ -15,21 +15,27 @@
+
@@ -54,30 +61,41 @@
-
diff --git a/tournaments/urls.py b/tournaments/urls.py index 78c4aa0..9e2eb75 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ path("", views.index, name="index"), path('tournament//', views.tournament, name='tournament'), path('tournament//summons/', views.tournament_summons, name='tournament-summons'), - path('tournament//json/', views.tournament_json, name='tournament-json'), + path('tournament//broadcast/', views.tournament_matches, name='tournament-matches'), + path('tournament//matches-json/', views.tournament_matches_json, name='tournament-matches-json'), path('players/', views.players, name='players'), ] diff --git a/tournaments/views.py b/tournaments/views.py index 4ed7f5e..0db06a3 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -48,12 +48,19 @@ def tournament_summons(request, tournament_id): 'team_summons': team_summons, }) -def tournament_json(request, tournament_id): + +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): + tournament = get_object_or_404(Tournament, pk=tournament_id) + return render(request, 'tournaments/broadcasted_matches.html', { + 'tournament': tournament, + }) + def players(request): return render(request, 'tournaments/test.html')