Merge branch 'master' into master

This commit is contained in:
Vincent 2018-08-29 17:58:29 +01:00 committed by GitHub
commit ac38a58a38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 14 deletions

View file

@ -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)

View file

@ -47,6 +47,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]
@ -184,6 +187,7 @@ def event_vote(request, event_id, poll_id):
if request.method == "POST":
ballot_json = json.loads(request.POST.get('ballot'))
selection = request.POST.get('selection')
encrypted_votes_json = ballot_json['encryptedVotes']
enc_ballot_json = request.POST.get('encBallot')
@ -213,6 +217,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)

View file

@ -28,9 +28,9 @@
</div>
<span><strong>Voting status:</strong>
{% if has_voted %}
Voted - Re-Submitting will Change your Vote
<span style="color: green; font-weight: bold">Voted - Re-submitting will change your vote</span>
{% else %}
Not Voted
<span style="color: red; font-weight: bold">Not Voted</span>
{% endif %}
</span>
<br/>
@ -105,13 +105,12 @@
</div>
<!-- Information Dialog called upon request -->
<div class="modal fade" id="modalDialog" role="dialog">
<div class="modal-dialog">
<div class="modal fade" id="modalDialog" role="dialog" tabindex="-1" data-backdrop="static">
<div class="modal-dialog" role="document">
<!-- Dialog content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title" style="text-align: center"><strong>Please Select a Ballot</strong></h4>
</div>
<div class="modal-body">
@ -125,7 +124,8 @@
</div>
</div>
<div class="modal-footer">
<button id="close-button" type="button" class="btn btn-danger" data-dismiss="modal">Close without submitting vote</button>
<button id="cancelVoteBtn" type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
<button id="closeDialogBtn" type="button" class="btn btn-primary hidden" data-dismiss="modal">Close</button>
</div>
</div>

View file

@ -8,4 +8,3 @@ django-simple-captcha
django-nocaptcha-recaptcha
django-recaptcha
mysqlclient

View file

@ -1,3 +1,5 @@
var dialogOpen = false;
function showDialogWithText(titleTxt, bodyTxt) {
var modalDialog = $('#modalDialog');
var title = modalDialog.find('.modal-title');
@ -10,7 +12,10 @@ function showDialogWithText(titleTxt, bodyTxt) {
body.empty();
body.append( p );
modalDialog.modal('show');
if(!dialogOpen) {
modalDialog.modal('toggle');
dialogOpen = true;
}
}
// This should stop people ticking more than the maximum permitted
@ -67,9 +72,16 @@ function isVotingInputValid() {
// This will highlight when people haven't selected enough options
if(!valid) {
let errText = "You've only selected " + selectedCount
+ " option(s). The minimum number you need to select is " + MIN_SELECTIONS
+ " and the maximum is " + MAX_SELECTIONS + ". Please go back and correct this.";
let errText = "You've only selected " + selectedCount;
if(selectedCount > 1) {
errText += " options.";
} else {
errText = " You haven't selected any options.";
}
errText += " The minimum number you need to select is " + MIN_SELECTIONS + " and the maximum is "
+ MAX_SELECTIONS + ". Please go back and correct this.";
let titleTxt = 'Voting Error';
@ -455,3 +467,29 @@ function onAfterBallotSend(ballotID, SK) {
modalDialog.modal('show');
}
$('#modalDialog').on('hide.bs.modal', function (e) {
var titleText = $(this).find('.modal-title').text();
if(titleText.indexOf("Received") > -1) {
// Update page to reflect the fact that a vote has taken place
location.reload();
} else {
// Reset poll voting to allow user to vote again
progressBar.setAttribute("style", "width: 0%;");
$('#gen-ballots-btn').toggleClass("hidden");
$('#progress-bar-description').toggleClass('hidden');
$('#progress-bar-container').toggleClass('hidden');
var inputs = $("label input[type=checkbox]");
inputs.each(function () {
var input = $(this);
input.prop('checked', false);
input.prop('disabled', false);
});
selectedCount = 0;
}
dialogOpen = false;
});