From b0e43959ebc96f8db30114dca724080b39c46465 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO <yohann.danello@animath.fr> Date: Mon, 18 Jan 2021 16:54:57 +0100 Subject: [PATCH] Don't display notes too early --- .../participation/tournament_detail.html | 30 ++++++++++--------- apps/participation/views.py | 10 +++++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/apps/participation/templates/participation/tournament_detail.html b/apps/participation/templates/participation/tournament_detail.html index 33bf9e6..b7fc4c4 100644 --- a/apps/participation/templates/participation/tournament_detail.html +++ b/apps/participation/templates/participation/tournament_detail.html @@ -61,9 +61,9 @@ {% render_table teams %} </div> - <hr> - {% if pools.data %} + <hr> + <h3>{% trans "Pools" %}</h3> <div id="pools_table"> {% render_table pools %} @@ -74,20 +74,22 @@ <button class="btn btn-block btn-success" data-toggle="modal" data-target="#addPoolModal">{% trans "Add new pool" %}</button> {% endif %} - <hr> + {% if notes %} + <hr> - <div class="card bg-light shadow"> - <div class="card-header text-center"> - <h5>{% trans "Ranking" %}</h5> + <div class="card bg-light shadow"> + <div class="card-header text-center"> + <h5>{% trans "Ranking" %}</h5> + </div> + <div class="card-body"> + <ul> + {% for participation, note in notes %} + <li><strong>{{ participation.team }} :</strong> {{ note }}</li> + {% endfor %} + </ul> + </div> </div> - <div class="card-body"> - <ul> - {% for participation, note in notes %} - <li><strong>{{ participation.team }} :</strong> {{ note }}</li> - {% endfor %} - </ul> - </div> - </div> + {% endif %} {% if user.registration.is_admin %} {% trans "Add pool" as modal_title %} diff --git a/apps/participation/views.py b/apps/participation/views.py index e0ad4db..aca6a90 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -466,8 +466,10 @@ class TournamentDetailView(DetailView): notes = dict() for participation in self.object.participations.all(): - notes[participation] = sum(pool.average(participation) - for pool in self.object.pools.filter(participations=participation).all()) + note = sum(pool.average(participation) + for pool in self.object.pools.filter(participations=participation).all()) + if note: + notes[participation] = note context["notes"] = sorted(notes.items(), key=lambda x: x[1], reverse=True) return context @@ -536,7 +538,9 @@ class PoolDetailView(LoginRequiredMixin, DetailView): notes = dict() for participation in self.object.participations.all(): - notes[participation] = self.object.average(participation) + note = self.object.average(participation) + if note: + notes[participation] = note context["notes"] = sorted(notes.items(), key=lambda x: x[1], reverse=True) return context