mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Merge branch 'Elections' into 'master'
Less precise election results See merge request !45
This commit is contained in:
commit
3f6199f6c2
@ -85,18 +85,22 @@ class Role(models.Model):
|
||||
def results(self, total_vote):
|
||||
results = {}
|
||||
total_vote *= self.max_choice
|
||||
if total_vote == 0:
|
||||
return None
|
||||
non_blank = 0
|
||||
for candidature in self.candidatures.all():
|
||||
cand_results = {}
|
||||
cand_results['vote'] = self.votes.filter(candidature=candidature).count()
|
||||
cand_results['percent'] = cand_results['vote'] * 100 / total_vote
|
||||
if total_vote == 0:
|
||||
cand_results['percent'] = 0
|
||||
else:
|
||||
cand_results['percent'] = cand_results['vote'] * 100 / total_vote
|
||||
non_blank += cand_results['vote']
|
||||
results[candidature.user.username] = cand_results
|
||||
results['total vote'] = total_vote
|
||||
results['blank vote'] = {'vote': total_vote - non_blank,
|
||||
'percent': (total_vote - non_blank) * 100 / total_vote}
|
||||
if total_vote == 0:
|
||||
results['blank vote'] = {'vote': 0, 'percent': 0}
|
||||
else:
|
||||
results['blank vote'] = {'vote': total_vote - non_blank,
|
||||
'percent': (total_vote - non_blank) * 100 / total_vote}
|
||||
return results
|
||||
|
||||
@property
|
||||
|
@ -301,7 +301,7 @@ th {
|
||||
{%- if election.is_vote_finished %}
|
||||
{%- set results = election_results[role.title]['blank vote'] %}
|
||||
<div class="election__results">
|
||||
<strong>{{ results.vote }} {% trans %}votes{% endtrans %} ({{ results.percent }} %)</strong>
|
||||
<strong>{{ results.vote }} {% trans %}votes{% endtrans %} ({{ "%.2f" % results.percent }} %)</strong>
|
||||
</div>
|
||||
{%- endif %}
|
||||
</td>
|
||||
@ -318,12 +318,14 @@ th {
|
||||
</div>
|
||||
<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>
|
||||
{%- if not election.is_vote_finished %}
|
||||
<q class="candidate__program">{{ candidature.program or '' }}</q>
|
||||
{%- endif %}
|
||||
{%- if user.can_edit(candidature) -%}
|
||||
{% if election.is_vote_editable %}
|
||||
<a href="{{url('election:update_candidate', candidature_id=candidature.id)}}">{% trans %}Edit{% endtrans %}</a>
|
||||
{% endif %}
|
||||
{% if election.can_candidate -%}
|
||||
{% if election.is_vote_editable -%}
|
||||
<a href="{{url('election:delete_candidate', candidature_id=candidature.id)}}">{% trans %}Delete{% endtrans %}</a>
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
@ -339,7 +341,7 @@ th {
|
||||
{%- if election.is_vote_finished %}
|
||||
{%- set results = election_results[role.title][candidature.user.username] %}
|
||||
<div class="election__results">
|
||||
<strong>{{ results.vote }} {% trans %}votes{% endtrans %} ({{ results.percent }} %)</strong>
|
||||
<strong>{{ results.vote }} {% trans %}votes{% endtrans %} ({{ "%.2f" % results.percent }} %)</strong>
|
||||
</div>
|
||||
{%- endif %}
|
||||
</li>
|
||||
@ -362,7 +364,9 @@ th {
|
||||
{%- if (election.can_candidate(user) and election.is_candidature_active) or (user.can_edit(election) and election.is_vote_editable) %}
|
||||
<a href="{{ url('election:candidate', election_id=object.id) }}">{% trans %}Candidate{% endtrans %}</a>
|
||||
{%- endif %}
|
||||
{%- if election.is_vote_editable %}
|
||||
<a href="{{ url('election:create_list', election_id=object.id) }}">{% trans %}Add a new list{% endtrans %}</a>
|
||||
{%- endif %}
|
||||
{%- if user.can_edit(election) %}
|
||||
{% if election.is_vote_editable %}
|
||||
<a href="{{ url('election:create_role', election_id=object.id) }}">{% trans %}Add a new role{% endtrans %}</a>
|
||||
|
@ -472,7 +472,7 @@ class CandidatureDeleteView(CanEditMixin, DeleteView):
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
self.object = self.get_object()
|
||||
self.election = self.object.role.election
|
||||
if not self.election.can_candidate:
|
||||
if not self.election.can_candidate or not self.election.is_vote_editable:
|
||||
raise PermissionDenied
|
||||
return super(CandidatureDeleteView, self).dispatch(request, *arg, **kwargs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user