From b574b13d4159356b704f2fa887300065d3b69434 Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Sun, 28 Nov 2010 11:02:52 -0800
Subject: [PATCH] Added choice to notify no one

---
 helios/forms.py |  4 ++--
 helios/views.py | 25 ++++++++++++++-----------
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/helios/forms.py b/helios/forms.py
index c15e5e0..e9e35c9 100644
--- a/helios/forms.py
+++ b/helios/forms.py
@@ -30,5 +30,5 @@ class EmailVotersForm(forms.Form):
 
 class TallyNotificationEmailForm(forms.Form):
   subject = forms.CharField(max_length=80)
-  body = forms.CharField(max_length=2000, widget=forms.Textarea)
-  send_to = forms.ChoiceField(label="Send To", choices= [('all', 'all voters'), ('voted', 'only voters who cast a ballot')])
+  body = forms.CharField(max_length=2000, widget=forms.Textarea, required=False)
+  send_to = forms.ChoiceField(label="Send To", choices= [('all', 'all voters'), ('voted', 'only voters who cast a ballot'), ('none', 'no one -- are you sure about this?')])
diff --git a/helios/views.py b/helios/views.py
index 1ba06ee..933b5f9 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -886,21 +886,24 @@ def combine_decryptions(request, election):
         'election' : election
         }
 
-      # exclude those who have not voted
-      if email_form.cleaned_data['send_to'] == 'voted':
-        voter_constraints_exclude = {'vote_hash' : None}
-      else:
-        voter_constraints_exclude = {}
+      # if the user opted for notifying no one, then we skip this step
+      if email_form.cleaned_data['send_to'] != 'none':
+        # exclude those who have not voted
+        if email_form.cleaned_data['send_to'] == 'voted':
+          voter_constraints_exclude = {'vote_hash' : None}
+        else:
+          voter_constraints_exclude = {}
       
-      # full-length email
-      tasks.voters_email.delay(election_id = election.id,
-                               subject_template = 'email/result_subject.txt',
-                               body_template = 'email/result_body.txt',
-                               extra_vars = extra_vars,
-                               voter_constraints_exclude = voter_constraints_exclude)
+        # full-length email
+        tasks.voters_email.delay(election_id = election.id,
+                                 subject_template = 'email/result_subject.txt',
+                                 body_template = 'email/result_body.txt',
+                                 extra_vars = extra_vars,
+                                 voter_constraints_exclude = voter_constraints_exclude)
 
       # rapid short-message notification
       # this inherently only applies to those who have voted (for the most part)
+      # and this is not configurable, this is ALWAYS sent
       tasks.voters_notify.delay(election_id = election.id,
                                 notification_template = 'notification/result.txt',
                                 extra_vars = extra_vars)
-- 
GitLab