From a97541064e7000162f4bb1a7f828f162cab18bcf Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 14 Jan 2021 18:43:53 +0100 Subject: [PATCH] Display notes --- apps/participation/models.py | 26 +++++----- apps/participation/tables.py | 29 ++++++++++-- .../participation/passage_detail.html | 47 ++++++++++++++++++- apps/participation/views.py | 3 +- apps/registration/tables.py | 2 +- 5 files changed, 88 insertions(+), 19 deletions(-) diff --git a/apps/participation/models.py b/apps/participation/models.py index 461b33b..41e7669 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -383,39 +383,39 @@ class Passage(models.Model): return sum(items) / len(items) if items else 0 @property - def average_defender_writing(self): + def average_defender_writing(self) -> int: return self.avg(note.defender_writing for note in self.notes.all()) @property - def average_defender_oral(self): + def average_defender_oral(self) -> int: return self.avg(note.defender_oral for note in self.notes.all()) @property - def average_defender(self): - return 2 * self.average_defender_writing + self.average_defender_oral + def average_defender(self) -> int: + return self.average_defender_writing + 2 * self.average_defender_oral @property - def average_opponent_writing(self): + def average_opponent_writing(self) -> int: return self.avg(note.opponent_writing for note in self.notes.all()) @property - def average_opponent_oral(self): + def average_opponent_oral(self) -> int: return self.avg(note.opponent_oral for note in self.notes.all()) @property - def average_opponent(self): - return 2 * self.average_opponent_writing + self.average_opponent_oral + def average_opponent(self) -> int: + return self.average_opponent_writing + 2 * self.average_opponent_oral @property - def average_reporter_writing(self): + def average_reporter_writing(self) -> int: return self.avg(note.reporter_writing for note in self.notes.all()) @property - def average_reporter_oral(self): + def average_reporter_oral(self) -> int: return self.avg(note.reporter_oral for note in self.notes.all()) @property - def average_reporter(self): + def average_reporter(self) -> int: return self.average_reporter_writing + self.average_reporter_oral def average(self, participation): @@ -588,6 +588,10 @@ class Note(models.Model): def __str__(self): return _("Notes of {jury} for {passage}").format(jury=self.jury, passage=self.passage) + def __bool__(self): + return any((self.defender_writing, self.defender_oral, self.opponent_writing, self.opponent_oral, + self.reporter_writing, self.reporter_oral)) + class Meta: verbose_name = _("note") verbose_name_plural = _("notes") diff --git a/apps/participation/tables.py b/apps/participation/tables.py index 8cbb34d..b3d1da1 100644 --- a/apps/participation/tables.py +++ b/apps/participation/tables.py @@ -6,7 +6,7 @@ from django.utils.text import format_lazy from django.utils.translation import gettext_lazy as _ import django_tables2 as tables -from .models import Pool, Team, Tournament +from .models import Note, Pool, Team, Tournament # noinspection PyTypeChecker @@ -19,7 +19,7 @@ class TeamTable(tables.Table): class Meta: attrs = { - 'class': 'table table condensed table-striped', + 'class': 'table table-condensed table-striped', } model = Team fields = ('name', 'trigram',) @@ -51,7 +51,7 @@ class ParticipationTable(tables.Table): class Meta: attrs = { - 'class': 'table table condensed table-striped', + 'class': 'table table-condensed table-striped', } model = Team fields = ('name', 'trigram', 'valid',) @@ -70,7 +70,7 @@ class TournamentTable(tables.Table): class Meta: attrs = { - 'class': 'table table condensed table-striped', + 'class': 'table table-condensed table-striped', } model = Tournament fields = ('name', 'date',) @@ -91,8 +91,27 @@ class PoolTable(tables.Table): class Meta: attrs = { - 'class': 'table table condensed table-striped', + 'class': 'table table-condensed table-striped', } model = Pool fields = ('teams', 'round', 'tournament',) template_name = 'django_tables2/bootstrap4.html' + + +class NoteTable(tables.Table): + jury = tables.Column( + attrs={ + "td": { + "class": "text-nowrap", + } + } + ) + + class Meta: + attrs = { + 'class': 'table table-condensed table-striped text-center', + } + model = Note + fields = ('jury', 'defender_writing', 'defender_oral', 'opponent_writing', 'opponent_oral', + 'reporter_writing', 'reporter_oral',) + template_name = 'django_tables2/bootstrap4.html' diff --git a/apps/participation/templates/participation/passage_detail.html b/apps/participation/templates/participation/passage_detail.html index 531b778..0fae622 100644 --- a/apps/participation/templates/participation/passage_detail.html +++ b/apps/participation/templates/participation/passage_detail.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% load i18n %} +{% load django_tables2 i18n %} {% block content %} {% trans "any" as any %} @@ -50,6 +50,51 @@ {% endif %} + {% if notes %} +
+ +

{% trans "Notes detail" %}

+ + {% render_table notes %} + +
+
+
+
{% trans "Average points for the defender writing:" %}
+
{{ passage.average_defender_writing }}/20
+ +
{% trans "Average points for the defender oral:" %}
+
{{ passage.average_defender_oral }}/16
+ +
{% trans "Average points for the opponent writing:" %}
+
{{ passage.average_opponent_writing }}/9
+ +
{% trans "Average points for the opponent oral:" %}
+
{{ passage.average_opponent_oral }}/10
+ +
{% trans "Average points for the reporter writing:" %}
+
{{ passage.average_reporter_writing }}/9
+ +
{% trans "Average points for the reporter oral:" %}
+
{{ passage.average_reporter_oral }}/10
+
+ +
+ +
+
{% trans "Defender points:" %}
+
{{ passage.average_defender }}/52
+ +
{% trans "Opponent points:" %}
+
{{ passage.average_opponent }}/29
+ +
{% trans "Reporter points:" %}
+
{{ passage.average_reporter }}/19
+
+
+
+ {% endif %} + {% if user.registration.is_admin %} {% trans "Update passage" as modal_title %} {% trans "Update" as modal_button %} diff --git a/apps/participation/views.py b/apps/participation/views.py index 70db0ea..36a1caf 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -26,7 +26,7 @@ from tfjm.views import AdminMixin from .forms import JoinTeamForm, NoteForm, ParticipationForm, PassageForm, PoolForm, PoolTeamsForm, \ RequestValidationForm, TeamForm, TournamentForm, ValidateParticipationForm, SolutionForm, SynthesisForm from .models import Note, Participation, Passage, Pool, Team, Tournament, Solution, Synthesis -from .tables import TeamTable, TournamentTable, ParticipationTable, PoolTable +from .tables import TeamTable, TournamentTable, ParticipationTable, PoolTable, NoteTable class CreateTeamView(LoginRequiredMixin, CreateView): @@ -517,6 +517,7 @@ class PassageDetailView(LoginRequiredMixin, DetailView): context = super().get_context_data(**kwargs) if self.request.user.registration in self.object.pool.juries.all(): context["my_note"] = Note.objects.get(passage=self.object, jury=self.request.user.registration) + context["notes"] = NoteTable([note for note in self.object.notes.all() if note]) return context diff --git a/apps/registration/tables.py b/apps/registration/tables.py index 7f18bd5..c20bcd1 100644 --- a/apps/registration/tables.py +++ b/apps/registration/tables.py @@ -20,7 +20,7 @@ class RegistrationTable(tables.Table): class Meta: attrs = { - 'class': 'table table condensed table-striped', + 'class': 'table table-condensed table-striped', } model = Registration fields = ('last_name', 'user__first_name', 'user__email', 'type',)