Skip to content

Commit

Permalink
added ability to email a single user
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Oct 8, 2011
1 parent 50d26c1 commit df703a7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions deploy-staging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
fab staging_deploy:tag=latest,hosts="server1.heliosvoting.org"
2 changes: 1 addition & 1 deletion helios/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion helios/templates/voters_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2 class="title">{{election.name}} &mdash; Contact Voters <span style="font-siz
{% 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 %}
Expand All @@ -42,6 +42,7 @@ <h2 class="title">{{election.name}} &mdash; Contact Voters <span style="font-siz
<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>
Expand Down
1 change: 1 addition & 0 deletions helios/templates/voters_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ <h2 class="title">{{election.name}} &mdash; Voters and Ballot Tracking Center <s
{% 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>
Expand Down
19 changes: 11 additions & 8 deletions helios/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit df703a7

Please sign in to comment.