Rajout des bulletins par classement

This commit is contained in:
Tom Hubrecht 2021-04-17 00:43:30 +02:00
parent 1cdb125356
commit 4c0611ac96
4 changed files with 49 additions and 5 deletions

View file

@ -0,0 +1,21 @@
{% load i18n %}
<table class="table is-striped is-fullwidth">
<thead>
<tr>
{% for o in options %}
<th>{{ o }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for ballot in ballots.values %}
<tr>
{% for r in ballot %}
<td class="has-text-centered">{{ r }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>

View file

@ -1,6 +1,6 @@
{% load i18n %}
<table class="table">
<table class="table is-striped is-fullwidth">
<thead>
<tr>
{% for o in options %}

View file

@ -29,8 +29,13 @@
<hr>
{# Tableau des bulletins par question #}
{% for q in election.questions.all %}
{{ q.display_ballots }}
{% endfor %}
<div class="columns is-centered is-multiline">
{% for q in election.questions.all %}
<div class="column is-narrow is-flex-shrink-1">
<p class="subtitle">{{ q.text }}</p>
{{ q.display_ballots }}
</div>
{% endfor %}
</div>
{% endblock %}

View file

@ -275,6 +275,7 @@ class BallotsData:
"""Classe pour afficher les bulletins d'une question"""
def select(question):
"""Renvoie un tableau affichant les options sélectionnées pour chaque bulletin"""
from .models import Vote
votes = Vote.objects.filter(option__question=question)
@ -293,7 +294,24 @@ class BallotsData:
)
def rank(question):
return ""
"""Renvoie un tableau contenant les classements des options par bulletin"""
from .models import Rank
options = list(question.options.all())
ranks = Rank.objects.select_related("vote").filter(vote__option__in=options)
ranks_by_user = {}
for r in ranks:
user = r.vote.user
if user in ranks_by_user:
ranks_by_user[user].append(r.rank)
else:
ranks_by_user[user] = [r.rank]
return render_to_string(
"elections/ballots/rank.html",
{"options": options, "ballots": ranks_by_user},
)
# #############################################################################