Display notes

This commit is contained in:
Yohann D'ANELLO 2021-01-14 18:43:53 +01:00
parent ef785a5eb8
commit a97541064e
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
5 changed files with 88 additions and 19 deletions

View File

@ -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")

View File

@ -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'

View File

@ -1,6 +1,6 @@
{% extends "base.html" %}
{% load i18n %}
{% load django_tables2 i18n %}
{% block content %}
{% trans "any" as any %}
@ -50,6 +50,51 @@
{% endif %}
</div>
{% if notes %}
<hr>
<h2>{% trans "Notes detail" %}</h2>
{% render_table notes %}
<div class="card bg-light shadow">
<div class="card-body">
<dl class="row">
<dt class="col-sm-8">{% trans "Average points for the defender writing:" %}</dt>
<dd class="col-sm-4">{{ passage.average_defender_writing }}/20</dd>
<dt class="col-sm-8">{% trans "Average points for the defender oral:" %}</dt>
<dd class="col-sm-4">{{ passage.average_defender_oral }}/16</dd>
<dt class="col-sm-8">{% trans "Average points for the opponent writing:" %}</dt>
<dd class="col-sm-4">{{ passage.average_opponent_writing }}/9</dd>
<dt class="col-sm-8">{% trans "Average points for the opponent oral:" %}</dt>
<dd class="col-sm-4">{{ passage.average_opponent_oral }}/10</dd>
<dt class="col-sm-8">{% trans "Average points for the reporter writing:" %}</dt>
<dd class="col-sm-4">{{ passage.average_reporter_writing }}/9</dd>
<dt class="col-sm-8">{% trans "Average points for the reporter oral:" %}</dt>
<dd class="col-sm-4">{{ passage.average_reporter_oral }}/10</dd>
</dl>
<hr>
<dl class="row">
<dt class="col-sm-8">{% trans "Defender points:" %}</dt>
<dd class="col-sm-4">{{ passage.average_defender }}/52</dd>
<dt class="col-sm-8">{% trans "Opponent points:" %}</dt>
<dd class="col-sm-4">{{ passage.average_opponent }}/29</dd>
<dt class="col-sm-8">{% trans "Reporter points:" %}</dt>
<dd class="col-sm-4">{{ passage.average_reporter }}/19</dd>
</dl>
</div>
</div>
{% endif %}
{% if user.registration.is_admin %}
{% trans "Update passage" as modal_title %}
{% trans "Update" as modal_button %}

View File

@ -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

View File

@ -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',)