On affiche l'abréviation dans le tableu des résultats

This commit is contained in:
Tom Hubrecht 2021-06-28 21:33:07 +02:00
parent 6ba5a5c620
commit 3601508ab2
5 changed files with 37 additions and 31 deletions

View file

@ -170,6 +170,9 @@ class Option(models.Model):
super().save(*args, **kwargs)
def get_abbr(self, default):
return self.abbreviation or default
def __str__(self):
if self.abbreviation:
return self.abbreviation + " - " + self.text

View file

@ -24,7 +24,6 @@
<tbody>
{% for line, o in matrix %}
{% with loser=forloop.counter %}
<tr>
<th class="has-text-centered">
<span class="icon-text">
@ -36,10 +35,9 @@
</th>
{% for cell, class in line %}
<td class="has-text-centered has-tooltip-primary {{ class }}" {% if cell %}data-tooltip="{% blocktrans with winner=forloop.counter %}L'option {{ winner }} est préférée à l'option {{ loser }} par {{ cell }} voix.{% endblocktrans %}{% endif %}">{{ cell }}</td>
<td class="has-text-centered has-tooltip-primary {{ class }}" {% if cell.value %}data-tooltip="{% blocktrans with winner=cell.winner loser=cell.loser value=cell.value %}L'option {{ winner }} est préférée à l'option {{ loser }} par {{ value }} voix.{% endblocktrans %}{% endif %}">{{ cell.value }}</td>
{% endfor %}
</tr>
{% endwith %}
{% endfor %}
</tbody>
</table>

View file

@ -238,18 +238,22 @@ class ResultsData:
options = list(question.options.all())
n = len(options)
_matrix = np.zeros((n, n), dtype=int)
matrix = np.zeros((n, n), dtype=tuple)
_matrix = np.full((n, n), {"value": 0}, dtype=dict)
matrix = np.empty((n, n), dtype=tuple)
for d in duels:
i, j = options.index(d.loser), options.index(d.winner)
_matrix[i, j] = d.amount
_matrix[i, j] = {
"value": d.amount,
"winner": d.winner.get_abbr(j + 1),
"loser": d.loser.get_abbr(i + 1),
}
for i in range(n):
for j in range(n):
if _matrix[i, j] > _matrix[j, i]:
if _matrix[i, j]["value"] > _matrix[j, i]["value"]:
matrix[i, j] = (_matrix[i, j], "is-success")
elif _matrix[i, j] < _matrix[j, i]:
elif _matrix[i, j]["value"] < _matrix[j, i]["value"]:
matrix[i, j] = (_matrix[i, j], "is-danger")
else:
matrix[i, j] = (_matrix[i, j], "")

View file

@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-06-18 22:33+0200\n"
"PO-Revision-Date: 2021-06-18 22:34+0200\n"
"POT-Creation-Date: 2021-06-28 21:29+0200\n"
"PO-Revision-Date: 2021-06-28 21:30+0200\n"
"Last-Translator: Test Translator <test@translator>\n"
"Language-Team: \n"
"Language: en\n"
@ -152,19 +152,19 @@ msgstr "winning option"
msgid "nombre de votes reçus"
msgstr "number of votes received"
#: elections/models.py:192
#: elections/models.py:195
msgid "rang de l'option"
msgstr "option's ranking"
#: elections/models.py:208
#: elections/models.py:211
msgid "votes supplémentaires"
msgstr "extra votes"
#: elections/models.py:224
#: elections/models.py:227
msgid "Nom et Prénom"
msgstr "Name and surname"
#: elections/models.py:247 elections/tests/test_models.py:57
#: elections/models.py:250 elections/tests/test_models.py:57
msgid "identifiants spécifiques"
msgstr "dedicated credentials"
@ -470,14 +470,15 @@ msgstr "Editing an option"
msgid "Modification d'une question"
msgstr "Editing a question"
#: elections/templates/elections/results/rank.html:39
#: elections/templates/elections/results/rank.html:38
#, python-format
msgid ""
"L'option %(winner)s est préférée à l'option %(loser)s par %(cell)s voix."
"L'option %(winner)s est préférée à l'option %(loser)s par %(value)s voix."
msgstr ""
"The %(winner)s option is preferred to the %(loser)s option by %(cell)s votes."
"The %(winner)s option is preferred to the %(loser)s option by %(value)s "
"votes."
#: elections/templates/elections/results/rank.html:51
#: elections/templates/elections/results/rank.html:49
msgid ""
"La matrice des résultats montre les points d'avance, l'option gagnante est "
"affichée sur la colonne et la perdante sur la ligne. "
@ -547,30 +548,30 @@ msgstr "Confirm"
msgid "Annuler"
msgstr "Cancel"
#: elections/templates/elections/vote/rank.html:154
#: elections/templates/elections/vote/rank.html:151
msgid "Classement"
msgstr "Ranking"
#: elections/templates/elections/vote/rank.html:155
#: elections/templates/elections/vote/rank.html:152
#: elections/templates/elections/vote/select.html:24
msgid "Option(s) selectionnée(s)"
msgstr "Selected option(s)"
#: elections/templates/elections/vote/rank.html:175
#: elections/templates/elections/vote/rank.html:228
#: elections/templates/elections/vote/rank.html:172
#: elections/templates/elections/vote/rank.html:225
msgid "Utiliser le formulaire classique"
msgstr "Use the traditional form"
#: elections/templates/elections/vote/rank.html:180
#: elections/templates/elections/vote/rank.html:177
msgid "Utiliser le cliquer-déposer"
msgstr "Use Drag & Drop"
#: elections/templates/elections/vote/rank.html:238
#: elections/templates/elections/vote/rank.html:235
#, python-format
msgid "Rang %(i)s"
msgstr "Rank %(i)s"
#: elections/templates/elections/vote/rank.html:249
#: elections/templates/elections/vote/rank.html:246
msgid "Ajouter un rang"
msgstr "Add an rank"
@ -590,7 +591,7 @@ msgstr "The maximum ranking is {}."
msgid "Le classement minimal est 1."
msgstr "The minimum ranking is 1."
#: elections/utils.py:335
#: elections/utils.py:339
msgid ""
"Format invalide. Vérifiez que le fichier est bien formé (i.e. chaque ligne "
"de la forme 'login,nom,email')."
@ -598,23 +599,23 @@ msgstr ""
"Invalid format. Check that the file is properly formed (i.e. each line of "
"the form 'login,name,e-mail')."
#: elections/utils.py:349
#: elections/utils.py:353
msgid "La ligne {} n'a pas le bon nombre d'éléments."
msgstr "The line {} has the wrong number of elements."
#: elections/utils.py:354
#: elections/utils.py:358
msgid "Valeur manquante dans la ligne {} : 'login'."
msgstr "Missing value in line {}: 'login'."
#: elections/utils.py:359
#: elections/utils.py:363
msgid "Doublon dans les logins : lignes {} et {}."
msgstr "Duplicate logins: lines {} and {}."
#: elections/utils.py:367
#: elections/utils.py:371
msgid "Valeur manquante dans la ligne {} : 'nom'."
msgstr "Missing value in line {}: 'name'."
#: elections/utils.py:373
#: elections/utils.py:377
msgid "Adresse mail invalide à la ligne {} : '{}'."
msgstr "Invalid e-mail address in line {}: '{}'."