From df703a7fad7e1cec51a1c6cba9ef2085b30e5220 Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Fri, 7 Oct 2011 21:53:03 -0700
Subject: [PATCH] added ability to email a single user

---
 deploy-staging.sh                  |  2 ++
 helios/forms.py                    |  2 +-
 helios/templates/voters_email.html |  3 ++-
 helios/templates/voters_list.html  |  1 +
 helios/views.py                    | 19 +++++++++++--------
 5 files changed, 17 insertions(+), 10 deletions(-)
 create mode 100755 deploy-staging.sh

diff --git a/deploy-staging.sh b/deploy-staging.sh
new file mode 100755
index 0000000..f278713
--- /dev/null
+++ b/deploy-staging.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+fab staging_deploy:tag=latest,hosts="server1.heliosvoting.org"
\ No newline at end of file
diff --git a/helios/forms.py b/helios/forms.py
index acc7a58..cf8422d 100644
--- a/helios/forms.py
+++ b/helios/forms.py
@@ -29,7 +29,7 @@ class ElectionTimesForm(forms.Form):
 class EmailVotersForm(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', 'voters who have cast a ballot'), ('not-voted', 'voters who have not yet cast a ballot')])
+  send_to = forms.ChoiceField(label="Send To", initial="all", choices= [('all', 'all voters'), ('voted', 'voters who have cast a ballot'), ('not-voted', 'voters who have not yet cast a ballot')])
 
 class TallyNotificationEmailForm(forms.Form):
   subject = forms.CharField(max_length=80)
diff --git a/helios/templates/voters_email.html b/helios/templates/voters_email.html
index 1c6155b..32a38ab 100644
--- a/helios/templates/voters_email.html
+++ b/helios/templates/voters_email.html
@@ -24,7 +24,7 @@ voter_id = '{{voter.voter_id}}';
 {% if template_option.0 == template %}
 <b>{{template_option.1}}</b>
 {% else %}
-<a href="?template={{template_option.0}}">{{template_option.1}}</a>
+<a href="?template={{template_option.0}}&voter_id={{voter.voter_login_id}}">{{template_option.1}}</a>
 {% endif %}
 &nbsp;&nbsp;&nbsp;
 {% endfor %}
@@ -42,6 +42,7 @@ You may tweak the subject and add a custom message using the form below.
   <form class="prettyform" action="" method="POST" id="email_form">
     <input type="hidden" name="csrf_token" value="{{csrf_token}}" />
     <input type="hidden" name="template" value="{{template}}" />
+    <input type="hidden" name="voter_id" value="{{voter.voter_login_id}}" />
     <table class="pretty">
      {{email_form.as_table}}
      </table>
diff --git a/helios/templates/voters_list.html b/helios/templates/voters_list.html
index 68d46cb..b5090a0 100644
--- a/helios/templates/voters_list.html
+++ b/helios/templates/voters_list.html
@@ -118,6 +118,7 @@ Voters {{voters_page.start_index}} - {{voters_page.end_index}} (of {{total_voter
 {% if admin_p or not election.use_voter_aliases %}
 <td>
 {% if admin_p %}
+[<a href="{% url helios.views.voters_email election.uuid %}?voter_id={{voter.voter_login_id}}">email</a>]
 [<a onclick="return confirm('are you sure you want to remove {{voter.name}} ?');" href="{% url helios.views.voter_delete election.uuid, voter.uuid %}">x</a>]
 {% endif %}
 <img border="0" height="20" src="/static/auth/login-icons/{{voter.voter_type}}.png" alt="{{voter.voter_type}}" /> {{voter.name}}</td>
diff --git a/helios/views.py b/helios/views.py
index 30fd9c2..9b463ed 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -1232,6 +1232,7 @@ def voters_email(request, election):
     raise Exception("bad template")
 
   voter_id = request.REQUEST.get('voter_id', None)
+
   if voter_id:
     voter = Voter.get_by_election_and_voter_id(election, voter_id)
   else:
@@ -1259,6 +1260,8 @@ def voters_email(request, election):
 
   if request.method == "GET":
     email_form = forms.EmailVotersForm()
+    if voter:
+      email_form.fields['send_to'].widget = email_form.fields['send_to'].hidden_widget()
   else:
     email_form = forms.EmailVotersForm(request.POST)
     
@@ -1279,17 +1282,17 @@ def voters_email(request, election):
       voter_constraints_include = None
       voter_constraints_exclude = None
 
-      # exclude those who have not voted
-      if email_form.cleaned_data['send_to'] == 'voted':
-        voter_constraints_exclude = {'vote_hash' : None}
-
-      # include only those who have not voted
-      if email_form.cleaned_data['send_to'] == 'not-voted':
-        voter_constraints_include = {'vote_hash': None}
-
       if voter:
         tasks.single_voter_email.delay(voter_uuid = voter.uuid, subject_template = subject_template, body_template = body_template, extra_vars = extra_vars)
       else:
+        # exclude those who have not voted
+        if email_form.cleaned_data['send_to'] == 'voted':
+          voter_constraints_exclude = {'vote_hash' : None}
+          
+        # include only those who have not voted
+        if email_form.cleaned_data['send_to'] == 'not-voted':
+          voter_constraints_include = {'vote_hash': None}
+
         tasks.voters_email.delay(election_id = election.id, subject_template = subject_template, body_template = body_template, extra_vars = extra_vars, voter_constraints_include = voter_constraints_include, voter_constraints_exclude = voter_constraints_exclude)
 
       # this batch process is all async, so we can return a nice note
-- 
GitLab