Commit 1c761f9d authored by Jean-Baptiste Lenglet's avatar Jean-Baptiste Lenglet Committed by Sli

Added results when the user is not voting

parent e8d54764
...@@ -57,10 +57,10 @@ class Election(models.Model): ...@@ -57,10 +57,10 @@ class Election(models.Model):
return False return False
@property @property
def get_results(self): def results(self):
results = {} results = {}
for role in self.role.all(): for role in self.role.all():
results[role.title] = role.get_results results[role.title] = role.results
return results return results
# Permissions # Permissions
...@@ -80,7 +80,7 @@ class Role(models.Model): ...@@ -80,7 +80,7 @@ class Role(models.Model):
return self.has_voted.filter(id=user.id).exists() return self.has_voted.filter(id=user.id).exists()
@property @property
def get_results(self): def results(self):
results = {} results = {}
total_vote = self.has_voted.count() * self.max_choice total_vote = self.has_voted.count() * self.max_choice
if total_vote == 0: if total_vote == 0:
......
...@@ -87,14 +87,18 @@ th { ...@@ -87,14 +87,18 @@ th {
} }
.list-per-role__candidate:not(:last-child) { .list-per-role__candidate:not(:last-child) {
margin-bottom: 5px; margin-bottom: 15px;
} }
.candidate { .candidate__infos {
display: flex; display: flex;
flex-flow: row nowrap; flex-flow: row nowrap;
} }
.candidate__infos:not(:last-child) {
margin-bottom: 5px;
}
.candidate__picture-wrapper { .candidate__picture-wrapper {
display: flex; display: flex;
justify-content: center; justify-content: center;
...@@ -113,7 +117,7 @@ th { ...@@ -113,7 +117,7 @@ th {
max-height: 150px; max-height: 150px;
} }
.candidate__infos { .candidate__details {
margin-left: 5px; margin-left: 5px;
} }
...@@ -184,6 +188,10 @@ th { ...@@ -184,6 +188,10 @@ th {
background: indianred; background: indianred;
} }
.election__results {
text-align: center;
}
.election__sumbit-section { .election__sumbit-section {
margin-bottom: 5px; margin-bottom: 5px;
} }
...@@ -251,9 +259,7 @@ th { ...@@ -251,9 +259,7 @@ th {
{%- set election_lists = election.election_list.all() -%} {%- set election_lists = election.election_list.all() -%}
<caption></caption> <caption></caption>
<thead> <thead>
{%- if not election.has_voted(user) and election.can_vote(user) %}
<th>{% trans %}Blank vote{% endtrans %}</th> <th>{% trans %}Blank vote{% endtrans %}</th>
{%- endif %}
{%- for election_list in election_lists %} {%- for election_list in election_lists %}
<th>{{election_list.title}}</th> <th>{{election_list.title}}</th>
{%- endfor %} {%- endfor %}
...@@ -276,29 +282,33 @@ th { ...@@ -276,29 +282,33 @@ th {
</td> </td>
</tr> </tr>
<tr class="role_candidates"> <tr class="role_candidates">
{%- if election.can_vote(user) %}
<td class="list-per-role"> <td class="list-per-role">
{%- if role.max_choice == 1 %} {%- if role.max_choice == 1 and election.can_vote(user) %}
<input id="id_{{ role.title }}_{{ count[0] }}" class="candidate__vote-input" type="radio" name="{{ role.title }}" value {{ '' if role_data in election_form else 'checked' }} {{ 'disabled' if election.has_voted(user) else '' }}> <input id="id_{{ role.title }}_{{ count[0] }}" class="candidate__vote-input" type="radio" name="{{ role.title }}" value {{ '' if role_data in election_form else 'checked' }} {{ 'disabled' if election.has_voted(user) else '' }}>
<label for="id_{{ role.title }}_{{ count[0] }}" class="candidate__vote-choice"> <label for="id_{{ role.title }}_{{ count[0] }}" class="candidate__vote-choice">
<span>{% trans %}Choose blank vote{% endtrans %}</span> <span>{% trans %}Choose blank vote{% endtrans %}</span>
</label> </label>
{%- set _ = count.append(count.pop() + 1) %} {%- set _ = count.append(count.pop() + 1) %}
{%- endif %} {%- endif %}
{%- if election.has_voted(user) or not election.is_vote_active %}
{%- set results = election_results[role.title]['blank vote'] %}
<div class="election__results">
<strong>{{results.vote}} {% trans %}votes{% endtrans %} ( {{results.percent}} %)</strong>
</div>
{%- endif %}
</td> </td>
{%- endif %}
{%- for election_list in election_lists %} {%- for election_list in election_lists %}
<td class="list-per-role"> <td class="list-per-role">
<ul class="list-per-role__candidates"> <ul class="list-per-role__candidates">
{%- for candidature in election_list.candidature.filter(role=role) %} {%- for candidature in election_list.candidature.filter(role=role) %}
<li class="list-per-role__candidate"> <li class="list-per-role__candidate candidate">
<figure class="candidate"> <figure class="candidate__infos">
<div class="candidate__picture-wrapper"> <div class="candidate__picture-wrapper">
{%- if candidature.user.profile_pict and user.is_subscriber_viewable %} {%- if candidature.user.profile_pict and user.is_subscriber_viewable %}
<img class="candidate__picture" src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}"> <img class="candidate__picture" src="{{candidature.user.profile_pict.get_download_url()}}" alt="{% trans %}Profile{% endtrans %}">
{%- endif %} {%- endif %}
</div> </div>
<figcaption class="candidate__infos"> <figcaption class="candidate__details">
<cite class="candidate__full-name">{{ candidature.user.first_name }} <em class="candidate__nick-name">{{candidature.user.nick_name or ''}} </em>{{ candidature.user.last_name }}</cite> <cite class="candidate__full-name">{{ candidature.user.first_name }} <em class="candidate__nick-name">{{candidature.user.nick_name or ''}} </em>{{ candidature.user.last_name }}</cite>
<q class="candidate__program">{{ candidature.program or '' }}</q> <q class="candidate__program">{{ candidature.program or '' }}</q>
</figcaption> </figcaption>
...@@ -309,6 +319,11 @@ th { ...@@ -309,6 +319,11 @@ th {
<span>{% trans %}Choose{% endtrans %} {{ candidature.user.nick_name or candidature.user.first_name }}</span> <span>{% trans %}Choose{% endtrans %} {{ candidature.user.nick_name or candidature.user.first_name }}</span>
</label> </label>
{%- set _ = count.append(count.pop() + 1) %} {%- set _ = count.append(count.pop() + 1) %}
{%- else %}
{%- set results = election_results[role.title][candidature.user.username] %}
<div class="election__results">
<strong>{{results.vote}} {% trans %}votes{% endtrans %} ( {{results.percent}} %)</strong>
</div>
{%- endif %} {%- endif %}
</li> </li>
{%- endfor %} {%- endfor %}
......
...@@ -114,6 +114,7 @@ class ElectionDetailView(CanViewMixin, DetailView): ...@@ -114,6 +114,7 @@ class ElectionDetailView(CanViewMixin, DetailView):
kwargs = super(ElectionDetailView, self).get_context_data(**kwargs) kwargs = super(ElectionDetailView, self).get_context_data(**kwargs)
kwargs['candidate_form'] = CandidateForm(self.get_object().id) kwargs['candidate_form'] = CandidateForm(self.get_object().id)
kwargs['election_form'] = VoteForm(self.get_object(), self.request.user) kwargs['election_form'] = VoteForm(self.get_object(), self.request.user)
kwargs['election_results'] = self.get_object().results
return kwargs return kwargs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment