forked from ifsc/helios-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglue.py
38 lines (28 loc) · 1.13 KB
/
glue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Glue some events together
"""
from django.utils.translation import ugettext as _
import helios.signals
import helios.views
from helios.view_utils import render_template_raw
def vote_cast_send_message(user, voter, election, cast_vote, **kwargs):
## FIXME: this doesn't work for voters that are not also users
# prepare the message
subject_template = 'email/cast_vote_subject.txt'
body_template = 'email/cast_vote_body.txt'
extra_vars = {
'election': election,
'voter': voter,
'cast_vote': cast_vote,
'cast_vote_url': helios.views.get_castvote_url(cast_vote),
'custom_subject': _("[vote cast] - %(election_name)s") % {'election_name' : election.name}
}
subject = render_template_raw(None, subject_template, extra_vars)
body = render_template_raw(None, body_template, extra_vars)
# send it via the notification system associated with the auth system
user.send_message(subject, body)
def election_tallied(election, **kwargs):
pass
def glue():
helios.signals.vote_cast.connect(vote_cast_send_message)
helios.signals.election_tallied.connect(election_tallied)