diff --git a/elections/templates/elections/ballots/rank.html b/elections/templates/elections/ballots/rank.html
new file mode 100644
index 0000000..149cd42
--- /dev/null
+++ b/elections/templates/elections/ballots/rank.html
@@ -0,0 +1,21 @@
+{% load i18n %}
+
+
+
+
+ {% for o in options %}
+ {{ o }} |
+ {% endfor %}
+
+
+
+
+ {% for ballot in ballots.values %}
+
+ {% for r in ballot %}
+ {{ r }} |
+ {% endfor %}
+
+ {% endfor %}
+
+
diff --git a/elections/templates/elections/ballots/select.html b/elections/templates/elections/ballots/select.html
index fceeec1..75cc51a 100644
--- a/elections/templates/elections/ballots/select.html
+++ b/elections/templates/elections/ballots/select.html
@@ -1,6 +1,6 @@
{% load i18n %}
-
+
{% for o in options %}
diff --git a/elections/templates/elections/election_ballots.html b/elections/templates/elections/election_ballots.html
index 5d768fe..31c080e 100644
--- a/elections/templates/elections/election_ballots.html
+++ b/elections/templates/elections/election_ballots.html
@@ -29,8 +29,13 @@
{# Tableau des bulletins par question #}
-{% for q in election.questions.all %}
-{{ q.display_ballots }}
-{% endfor %}
+
+ {% for q in election.questions.all %}
+
+
{{ q.text }}
+ {{ q.display_ballots }}
+
+ {% endfor %}
+
{% endblock %}
diff --git a/elections/utils.py b/elections/utils.py
index 708753b..5c21b14 100644
--- a/elections/utils.py
+++ b/elections/utils.py
@@ -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},
+ )
# #############################################################################