From 1c761f9db29de9cf87828376429bc87e18c14672 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lenglet Date: Fri, 23 Dec 2016 20:40:54 +0100 Subject: [PATCH] Added results when the user is not voting --- election/models.py | 6 +-- .../templates/election/election_detail.jinja | 37 +++++++++++++------ election/views.py | 1 + 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/election/models.py b/election/models.py index c6df8537..00ca2f46 100644 --- a/election/models.py +++ b/election/models.py @@ -57,10 +57,10 @@ class Election(models.Model): return False @property - def get_results(self): + def results(self): results = {} for role in self.role.all(): - results[role.title] = role.get_results + results[role.title] = role.results return results # Permissions @@ -80,7 +80,7 @@ class Role(models.Model): return self.has_voted.filter(id=user.id).exists() @property - def get_results(self): + def results(self): results = {} total_vote = self.has_voted.count() * self.max_choice if total_vote == 0: diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja index 02334bf4..c5e5fbfd 100644 --- a/election/templates/election/election_detail.jinja +++ b/election/templates/election/election_detail.jinja @@ -87,14 +87,18 @@ th { } .list-per-role__candidate:not(:last-child) { - margin-bottom: 5px; + margin-bottom: 15px; } -.candidate { +.candidate__infos { display: flex; flex-flow: row nowrap; } +.candidate__infos:not(:last-child) { + margin-bottom: 5px; +} + .candidate__picture-wrapper { display: flex; justify-content: center; @@ -113,7 +117,7 @@ th { max-height: 150px; } -.candidate__infos { +.candidate__details { margin-left: 5px; } @@ -184,6 +188,10 @@ th { background: indianred; } +.election__results { + text-align: center; +} + .election__sumbit-section { margin-bottom: 5px; } @@ -251,9 +259,7 @@ th { {%- set election_lists = election.election_list.all() -%} - {%- if not election.has_voted(user) and election.can_vote(user) %} {% trans %}Blank vote{% endtrans %} - {%- endif %} {%- for election_list in election_lists %} {{election_list.title}} {%- endfor %} @@ -276,29 +282,33 @@ th { - {%- if election.can_vote(user) %} - {%- if role.max_choice == 1 %} + {%- if role.max_choice == 1 and election.can_vote(user) %} {%- set _ = count.append(count.pop() + 1) %} {%- endif %} + {%- if election.has_voted(user) or not election.is_vote_active %} + {%- set results = election_results[role.title]['blank vote'] %} +
+ {{results.vote}} {% trans %}votes{% endtrans %} ( {{results.percent}} %) +
+ {%- endif %} - {%- endif %} {%- for election_list in election_lists %}