From 3934b46ec03603980e0f11716864b79c9f272a7c Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Mon, 14 Feb 2011 21:44:17 -0800 Subject: [PATCH] fixed views, fixed eligibility legacy objects --- helios/datatypes/legacy.py | 5 ++- helios/models.py | 4 +-- helios/templates/_castconfirm_docast.html | 13 ++++++++ helios/templates/election_cast_confirm.html | 34 +++++---------------- helios/tests.py | 5 +++ helios/views.py | 1 + 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/helios/datatypes/legacy.py b/helios/datatypes/legacy.py index a9fe994..518a47d 100644 --- a/helios/datatypes/legacy.py +++ b/helios/datatypes/legacy.py @@ -190,6 +190,5 @@ class Tally(LegacyObject): STRUCTURED_FIELDS = { 'tally': arrayOf(arrayOf('legacy/EGCiphertext'))} - -class Eligibility(LegacyObject): - pass +class Eligibility(ListObject, LegacyObject): + WRAPPED_OBJ = list diff --git a/helios/models.py b/helios/models.py index 7765b00..c6e8069 100644 --- a/helios/models.py +++ b/helios/models.py @@ -344,8 +344,8 @@ class Election(HeliosModel): return auth_systems = copy.copy(settings.AUTH_ENABLED_AUTH_SYSTEMS) - voter_types = [r['user__user_type'] for r in self.voter_set.values('user__user_type').distinct()] - + voter_types = [r['user__user_type'] for r in self.voter_set.values('user__user_type').distinct() if r['user__user_type'] != None] + # password is now separate, not an explicit voter type if self.voter_set.filter(user=None).count() > 0: voter_types.append('password') diff --git a/helios/templates/_castconfirm_docast.html b/helios/templates/_castconfirm_docast.html index 18acbd0..8609cd1 100644 --- a/helios/templates/_castconfirm_docast.html +++ b/helios/templates/_castconfirm_docast.html @@ -1,3 +1,6 @@ +{% if election.voting_has_started %} + {% if not election.voting_has_stopped %} + <div id="cast_form"> <form method="post" action="" onsubmit="show_waiting()"> <input type="hidden" name="csrf_token" value="{{csrf_token}}" /> @@ -28,3 +31,13 @@ Verifying and Casting your ballot<br /> <img src="/static/helios/loading.gif" /> </div> + {% else %} +<p style="font-size:1.4em;"> + voting has stopped, sorry. +</p> + {% endif %} +{% else %} +<p style="font-size:1.4em;"> + voting has not yet begun, sorry. +</p> +{% endif %} diff --git a/helios/templates/election_cast_confirm.html b/helios/templates/election_cast_confirm.html index 5621d85..118d7c2 100644 --- a/helios/templates/election_cast_confirm.html +++ b/helios/templates/election_cast_confirm.html @@ -42,34 +42,18 @@ Your smart ballot tracker is:<br /><br /> <tt style="font-size:1.8em; font-weight: bold; padding-left: 20px;"> {{vote_fingerprint}}</tt> </p> -{% if password_only %} {% if voter %} -{% include "_castconfirm_docast.html" %} -{% else %} -{% include "_castconfirm_password.html" %} -{% endif %} -{% else %} +{% include "_castconfirm_docast.html" %} -{% if user %} +{% else %} -{% if voter %} +{% if show_password %} +{% include "_castconfirm_password.html" %} -{% if election.voting_has_started %} - {% if not election.voting_has_stopped %} - {% include "_castconfirm_docast.html" %} - {% else %} -<p style="font-size:1.4em;"> - voting has stopped, sorry. -</p> - {% endif %} {% else %} -<p style="font-size:1.4em;"> - voting has not yet begun, sorry. -</p> -{% endif %} -{% else %} +{% if user %} <p> {% if election.openreg %} <b>Sorry, you are <em><u>not eligible</u></em> for this election.</b><br /> @@ -80,8 +64,6 @@ Your smart ballot tracker is:<br /><br /> <p> [<a href="{% url helios.views.one_election_view election.uuid %}">return to the main election page</a>] </p> -{% endif %} - {% else %} <p> Now, we need you to log in, so we can verify your eligibility.<br /><br /> @@ -98,16 +80,14 @@ the same account you registered with. {% endif %} </p> -{% if show_password %} -{% include "_castconfirm_password.html" %} -{% endif %} - {{login_box|safe}} <br /> Don't worry, we'll remember your ballot while you log in. {% endif %} +{% endif %} + {# this closes the IF ELSE of this being password_only #} {% endif %} diff --git a/helios/tests.py b/helios/tests.py index 3d17ab4..cdddb60 100644 --- a/helios/tests.py +++ b/helios/tests.py @@ -118,6 +118,11 @@ class ElectionModelTests(TestCase): # without openreg, this should be false self.assertFalse(self.election.user_eligible_p(self.user)) + # what about after saving? + self.election.save() + e = models.Election.objects.get(uuid = self.election.uuid) + self.assertEquals(e.eligibility, [{'auth_system': self.user.user_type}]) + self.election.openreg = True # without openreg, and now true diff --git a/helios/views.py b/helios/views.py index bddd310..0298b0b 100644 --- a/helios/views.py +++ b/helios/views.py @@ -571,6 +571,7 @@ def one_election_cast_confirm(request, election): auth_systems = None password_only = False + if auth_systems == None or 'password' in auth_systems: show_password = True password_login_form = forms.VoterPasswordForm() -- GitLab