From 572600408c56b9c0b1d6908cf5bddc1a2bba4642 Mon Sep 17 00:00:00 2001 From: vince0656 Date: Wed, 22 Aug 2018 17:39:41 +0100 Subject: [PATCH] Updated polls/models to include a field for storing the ballot selected by the user on the front end. A few bugs have been fixed on the event voting page and new functionality has been added which allows a voter to restart the voting process. --- allauthdemo/polls/models.py | 1 + allauthdemo/polls/views.py | 5 ++ allauthdemo/templates/polls/event_vote.html | 13 ++-- requirements.txt | 3 +- static/js/event_vote.js | 85 ++++++++++++++++----- 5 files changed, 81 insertions(+), 26 deletions(-) diff --git a/allauthdemo/polls/models.py b/allauthdemo/polls/models.py index 581e88e..6e3d038 100755 --- a/allauthdemo/polls/models.py +++ b/allauthdemo/polls/models.py @@ -205,6 +205,7 @@ class PartialBallotDecryption(models.Model): class Ballot(models.Model): voter = models.ForeignKey(EmailUser, on_delete=models.CASCADE, related_name="ballots") poll = models.ForeignKey(Poll, on_delete=models.CASCADE, related_name="ballots") + selection = models.CharField(max_length=1) cast = models.BooleanField(default=False) diff --git a/allauthdemo/polls/views.py b/allauthdemo/polls/views.py index a09e6c2..24e80de 100755 --- a/allauthdemo/polls/views.py +++ b/allauthdemo/polls/views.py @@ -45,6 +45,9 @@ class EventDetailView(generic.DetailView): for poll in polls: result_json = poll.result_json + if result_json is None: + continue + if result_json[len(result_json)-1] == ',': result_json = result_json[0:len(result_json)-1] @@ -173,6 +176,7 @@ def event_vote(request, event_id, poll_id): if request.method == "POST": data = json.loads(request.POST.lists()[0][0]) + selection = data['selection'] ballot_json = data['ballot'] encrypted_votes_json = ballot_json['encryptedVotes'] @@ -191,6 +195,7 @@ def event_vote(request, event_id, poll_id): cipher_text_c2=fragment['C2']) ballot.cast = True + ballot.selection = selection ballot.save() combine_encrypted_votes.delay(email_key[0].user, poll) diff --git a/allauthdemo/templates/polls/event_vote.html b/allauthdemo/templates/polls/event_vote.html index d186ad3..f271669 100755 --- a/allauthdemo/templates/polls/event_vote.html +++ b/allauthdemo/templates/polls/event_vote.html @@ -28,9 +28,9 @@ Voting status: {% if has_voted %} - Voted - Re-Submitting will Change your Vote + Voted - Re-submitting will change your vote {% else %} - Not Voted + Not Voted {% endif %}
@@ -104,13 +104,12 @@ -