diff --git a/election/models.py b/election/models.py index 9e3cdf15..0d382db0 100644 --- a/election/models.py +++ b/election/models.py @@ -27,7 +27,7 @@ class Election(models.Model): return self.title @property - def is_active(self): + def is_vote_active(self): now = timezone.now() return bool(now <= self.end_date and now >= self.start_date) @@ -49,6 +49,8 @@ class Election(models.Model): return False def can_vote(self, user): + if not self.is_vote_active or self.has_voted(user): + return False for group in self.vote_groups.all(): if user.is_in_group(group): return True diff --git a/election/templates/election/election_detail.jinja b/election/templates/election/election_detail.jinja index ae02c435..8f424f2a 100644 --- a/election/templates/election/election_detail.jinja +++ b/election/templates/election/election_detail.jinja @@ -224,13 +224,23 @@ th {

{{ election.description }}


-

+

+ {%- if election.is_vote_active %} {% trans %}Polls close {% endtrans %} + {%- else %} + {% trans %}Polls will open {% endtrans %} + at + {% trans %}and will close {% endtrans %} + {%- endif %} at

- {%- if election.has_voted(request.user) %} + {%- if election.has_voted(user) %}

+ {%- if election.is_vote_active %} {% trans %}You already have submitted your vote.{% endtrans %} + {%- else %} + {% trans %}You have voted in this election.{% endtrans %} + {%- endif %}

{%- endif %}
@@ -241,7 +251,7 @@ th { {%- set election_lists = election.election_list.all() -%} - {%- if not election.has_voted(request.user) %} + {%- if not election.has_voted(user) %} {% trans %}Blank vote{% endtrans %} {%- endif %} {%- for election_list in election_lists %} @@ -255,7 +265,7 @@ th { {{role.title}} - {%- if role.max_choice > 1 and not election.has_voted(request.user) %} + {%- if role.max_choice > 1 and not election.has_voted(user) %} {% trans %}You may choose up to{% endtrans %} {{ role.max_choice }} {% trans %}people.{% endtrans %} {%- endif %} {%- if election_form.errors[role.title] is defined %} @@ -266,10 +276,10 @@ th { - {%- if not election.has_voted(request.user) %} + {%- if election.can_vote(user) %} - {%- if election.is_active and role.max_choice == 1 %} - + {%- if role.max_choice == 1 %} + @@ -293,8 +303,8 @@ th { {{ candidature.program or '' }} - {%- if election.is_active and not election.has_voted(request.user) %} - + {%- if election.can_vote(user) %} + @@ -311,18 +321,18 @@ th { - {%- if not election.has_voted(request.user) %} + {%- if not election.has_voted(user) %}
{%- endif %} - {%- if request.user.can_edit(election) %} + {%- if user.can_edit(election) %}
{% trans %}Add a new list{% endtrans %} {% trans %}Add a new role{% endtrans %}
{%- endif %} - {%- if election.can_candidate(request.user) %} + {%- if election.can_candidate(user) or user.can_edit(election) %}
{{candidate_form}} {% csrf_token %} diff --git a/election/views.py b/election/views.py index b8072e86..95665f7a 100644 --- a/election/views.py +++ b/election/views.py @@ -100,6 +100,7 @@ class ElectionDetailView(CanViewMixin, DetailView): kwargs = super(ElectionDetailView, self).get_context_data(**kwargs) kwargs['candidate_form'] = CandidateForm(self.get_object().id) kwargs['election_form'] = VoteForm(self.get_object(), self.request.user) + kwargs['user'] = self.request.user return kwargs