From df703a7fad7e1cec51a1c6cba9ef2085b30e5220 Mon Sep 17 00:00:00 2001 From: Ben Adida 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 000000000..f27871362 --- /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 acc7a58c9..cf8422d4c 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 1c6155ba9..32a38ab29 100644 --- a/helios/templates/voters_email.html +++ b/helios/templates/voters_email.html @@ -24,7 +24,7 @@

{{election.name}} — Contact Voters {{template_option.1}} +{{template_option.1}} {% endif %}     {% endfor %} @@ -42,6 +42,7 @@

{{election.name}} — Contact Voters + {{email_form.as_table}}
diff --git a/helios/templates/voters_list.html b/helios/templates/voters_list.html index 68d46cb3d..b5090a088 100644 --- a/helios/templates/voters_list.html +++ b/helios/templates/voters_list.html @@ -118,6 +118,7 @@

{{election.name}} — Voters and Ballot Tracking Center {% if admin_p %} +[email] [x] {% endif %} {{voter.voter_type}} {{voter.name}} diff --git a/helios/views.py b/helios/views.py index 30fd9c2a2..9b463ed41 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