From f9e73d16f29865611d4cd29f7859bdf7f9f3047f Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Sat, 15 Mar 2014 16:48:58 -0700 Subject: [PATCH] allowing for emails to go out without individual queueing --- helios/tasks.py | 13 ++++++++++++- settings.py | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/helios/tasks.py b/helios/tasks.py index 43ca5f6..75318b1 100644 --- a/helios/tasks.py +++ b/helios/tasks.py @@ -13,6 +13,7 @@ import signals import copy +from django.conf import settings @task() def cast_vote_verify_and_store(cast_vote_id, status_update_message=None, **kwargs): @@ -52,7 +53,17 @@ def voters_email(election_id, subject_template, body_template, extra_vars={}, voters = voters.exclude(**voter_constraints_exclude) for voter in voters: - single_voter_email.delay(voter.uuid, subject_template, body_template, extra_vars) + if settings.QUEUE_INDIVIDUAL_EMAILS: + single_voter_email.delay(voter.uuid, subject_template, body_template, extra_vars) + else: + the_vars = copy.copy(extra_vars) + the_vars.update({'voter' : voter}) + + subject = render_template_raw(None, subject_template, the_vars) + body = render_template_raw(None, body_template, the_vars) + + voter.user.send_message(subject, body) + @task() def voters_notify(election_id, notification_template, extra_vars={}): diff --git a/settings.py b/settings.py index 5c90c6a..3314019 100644 --- a/settings.py +++ b/settings.py @@ -155,6 +155,9 @@ DEFAULT_FROM_EMAIL = get_from_env('DEFAULT_FROM_EMAIL', 'ben@adida.net') DEFAULT_FROM_NAME = get_from_env('DEFAULT_FROM_NAME', 'Ben for Helios') SERVER_EMAIL = '%s <%s>' % (DEFAULT_FROM_NAME, DEFAULT_FROM_EMAIL) +# do we queue up each email as a job, or one job for all emails for a given election? +QUEUE_INDIVIDUAL_EMAILS = (get_from_env('QUEUE_INDIVIDUAL_EMAILS', '1') == '1') + LOGIN_URL = '/auth/' LOGOUT_ON_CONFIRMATION = True -- GitLab