basic email templating
Change-Id: I6be5ac18ee9760a39b026a71106970c31f4e0ac5
This commit is contained in:
parent
b86c3ae8e7
commit
69c8435a5b
|
@ -0,0 +1,15 @@
|
|||
Hello,
|
||||
|
||||
Your registrations with our service is almost done.
|
||||
|
||||
The action you have requested is:
|
||||
{% for action in actions %}
|
||||
- {{ action }}
|
||||
{% endfor %}
|
||||
|
||||
You token to complete this action is:
|
||||
{{ token }}
|
||||
|
||||
|
||||
Thank you for using our service.
|
||||
|
|
@ -24,6 +24,7 @@ from django.core.mail import send_mail
|
|||
from smtplib import SMTPException
|
||||
|
||||
from django.conf import settings
|
||||
from django.template import loader, Context
|
||||
|
||||
|
||||
@decorator
|
||||
|
@ -82,10 +83,12 @@ def create_token(registration):
|
|||
def email_token(registration, token):
|
||||
|
||||
emails = set()
|
||||
actions = []
|
||||
for action in registration.actions:
|
||||
act = action.get_action()
|
||||
if act.need_token:
|
||||
emails.add(act.token_email())
|
||||
actions.append(unicode(act))
|
||||
|
||||
if len(emails) > 1:
|
||||
notes = {
|
||||
|
@ -97,8 +100,12 @@ def email_token(registration, token):
|
|||
# TODO(adriant): raise some error?
|
||||
# and surround calls to this function with try/except
|
||||
|
||||
context = {'actions': actions, 'token': token.token}
|
||||
|
||||
email_template = loader.get_template("token.txt")
|
||||
|
||||
try:
|
||||
message = "your token is: %s" % token.token
|
||||
message = email_template.render(Context(context))
|
||||
send_mail(
|
||||
'Your token', message, 'no-reply@example.com',
|
||||
[emails.pop()], fail_silently=False)
|
||||
|
|
Loading…
Reference in New Issue