diff --git a/election/models.py b/election/models.py index 635ec7e5..b2659424 100644 --- a/election/models.py +++ b/election/models.py @@ -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 diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja index 777c00d8..5f2b4e57 100644 --- a/election/templates/election/election_detail.jinja +++ b/election/templates/election/election_detail.jinja @@ -301,7 +301,7 @@ th { {%- if election.is_vote_finished %} {%- set results = election_results[role.title]['blank vote'] %}
{{ candidature.program or '' }}+ {%- endif %} {%- if user.can_edit(candidature) -%} {% if election.is_vote_editable %} {% trans %}Edit{% endtrans %} {% endif %} - {% if election.can_candidate -%} + {% if election.is_vote_editable -%} {% trans %}Delete{% endtrans %} {%- endif -%} {%- endif -%} @@ -339,7 +341,7 @@ th { {%- if election.is_vote_finished %} {%- set results = election_results[role.title][candidature.user.username] %}