From 89362bae796d12bae81017ed0e1370238a0067a4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lenglet Date: Thu, 22 Dec 2016 22:17:22 +0100 Subject: [PATCH] Hide inputs when user already voted. --- election/models.py | 2 +- .../templates/election/election_detail.jinja | 37 ++++++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/election/models.py b/election/models.py index 525dc7a4..79e593b1 100644 --- a/election/models.py +++ b/election/models.py @@ -37,7 +37,7 @@ class Election(models.Model): return bool(now <= self.end_candidature and now >= self.start_candidature) def has_voted(self, user): - return hasattr(user, 'has_voted') and user.has_voted.all() == list(self.role.all()) + return hasattr(user, 'has_voted') and list(user.has_voted.all()) == list(self.role.all()) def can_candidate(self, user): for group in self.candidature_groups.all(): diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja index 43a07ce3..4eb2ad9f 100644 --- a/election/templates/election/election_detail.jinja +++ b/election/templates/election/election_detail.jinja @@ -23,21 +23,26 @@ th { .election__title { margin: 0; + margin-bottom: 5px; } .election__description { margin: 0; - margin-top: 5px; } .election__details { + margin-bottom: 5px; +} + +.election__details p { margin: 0; +} + +.election__details p:not(:last-child) { margin-bottom: 5px; } .election__elector-infos { - margin: 0; - margin-bottom: 5px; font-weight: bolder; color: darkgreen; } @@ -148,8 +153,8 @@ th { font-weight: bolder; } -.candidate__vote-input:not(:disabled:checked) + .candidate__vote-choice:hover, -.candidate__vote-input:not(:disabled:checked) + .candidate__vote-choice:focus { +.candidate__vote-input:not(:checked):not(:disabled) + .candidate__vote-choice:hover, +.candidate__vote-input:not(:checked):not(:disabled) + .candidate__vote-choice:focus { background: lightgrey; } @@ -180,7 +185,7 @@ th { } .election__sumbit-section { - margin-top: 5px; + margin-bottom: 5px; } .election__sumbit-button { @@ -200,6 +205,10 @@ th { background-color: lightskyblue; } +.election__add-elements { + margin-bottom: 5px; +} + .election__add-elements a { display: inline-block; border: solid 1px darkgrey; @@ -207,10 +216,6 @@ th { line-height: 20px; padding: 10px; } - -.election__add-candidature { - margin-top: 5px; -} {%- endblock %} @@ -218,8 +223,8 @@ th {

{{ election.title }}

{{ election.description }}


-
-

+

+

{% trans %}Polls close {% endtrans %} at

@@ -236,7 +241,9 @@ th { {%- set election_lists = election.election_list.all() -%} + {%- if not election.has_voted(request.user) %} {% trans %}Blank vote{% endtrans %} + {%- endif %} {%- for election_list in election_lists %} {{election_list.title}} {%- endfor %} @@ -248,7 +255,7 @@ th { {{role.title}} - {%- if role.max_choice > 1 %} + {%- if role.max_choice > 1 and not election.has_voted(request.user) %} {% trans %}You may choose up to{% endtrans %} {{ role.max_choice }} {% trans %}people.{% endtrans %} {%- endif %} {%- if election_form.errors[role.title] is defined %} @@ -259,6 +266,7 @@ th { + {%- if not election.has_voted(request.user) %} {%- if election.is_active and role.max_choice == 1 %} @@ -268,6 +276,7 @@ th { {%- set _ = count.append(count.pop() + 1) %} {%- endif %} + {%- endif %} {%- for election_list in election_lists %}
    @@ -284,7 +293,7 @@ th { {{ candidature.program or '' }} - {%- if election.is_active %} + {%- if election.is_active and not election.has_voted(request.user) %}