Skip to content
Snippets Groups Projects
Commit 5ce4129b authored by Ben Adida's avatar Ben Adida
Browse files

added ability to filter email to only those who have / have not voted, added...

added ability to filter email to only those who have / have not voted, added ability to suppress election links in mass email.
parent 525ea3ad
No related branches found
No related tags found
No related merge requests found
......@@ -25,4 +25,5 @@ class ElectionTimesForm(forms.Form):
class EmailVotersForm(forms.Form):
subject = forms.CharField(max_length=80)
body = forms.CharField(max_length=2000, widget=forms.Textarea)
suppress_election_links = forms.BooleanField(label = "Suppress links?", required=False)
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')])
......@@ -36,9 +36,22 @@ def cast_vote_verify_and_store(cast_vote_id, status_update_message=None, **kwarg
logger.error("Failed to verify and store %d" % cast_vote_id)
@task()
def voters_email(election_id, subject_template, body_template, extra_vars={}):
def voters_email(election_id, subject_template, body_template, extra_vars={},
voter_constraints_include=None, voter_constraints_exclude=None):
"""
voter_constraints_include are conditions on including voters
voter_constraints_exclude are conditions on excluding voters
"""
election = Election.objects.get(id = election_id)
for voter in election.voter_set.all():
# select the right list of voters
voters = election.voter_set.all()
if voter_constraints_include:
voters = voters.filter(**voter_constraints_include)
if voter_constraints_exclude:
voters = voters.exclude(**voter_constraints_exclude)
for voter in voters:
single_voter_email.delay(voter.uuid, subject_template, body_template, extra_vars)
@task()
......
......@@ -10,7 +10,7 @@ Your password: {{voter.user.info.password}}
{% else %}
Log in with your {{voter.voter_type}} account.
{% endifequal %}{% if voter.vote_hash %}
We have a vote recorded for you already, with smart tracker:
We have recorded your vote with smart tracker:
{{voter.vote_hash}}
......
Dear {{voter.name}},
{{custom_message|safe}}
--
Helios
......@@ -943,7 +943,7 @@ def voters_email(request, election):
voter = Voter.get_by_election_and_voter_id(election, voter_id)
if request.method == "GET":
email_form = forms.EmailVotersForm({'subject': 'Vote in %s' % election.name, 'body':' '})
email_form = forms.EmailVotersForm(initial={'subject': 'Vote in %s' % election.name})
else:
email_form = forms.EmailVotersForm(request.POST)
......@@ -953,6 +953,9 @@ def voters_email(request, election):
subject_template = 'email/vote_subject.txt'
body_template = 'email/vote_body.txt'
if email_form.cleaned_data['suppress_election_links']:
body_template = 'email/vote_body_nolinks.txt'
extra_vars = {
'custom_subject' : email_form.cleaned_data['subject'],
'custom_message' : email_form.cleaned_data['body'],
......@@ -960,11 +963,21 @@ def voters_email(request, election):
'election' : 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:
tasks.voters_email.delay(election_id = election.id, subject_template = subject_template, body_template = body_template, extra_vars = extra_vars)
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
return HttpResponseRedirect(reverse(one_election_view, args=[election.uuid]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment