- def send(self, recipient, verbose=False, dry_run=False):
- subject = Template(self.subject).render(Context(recipient.context))
- body = Template(self.body).render(Context(recipient.context))
+ def send(self, recipient, verbose=False, dry_run=False, test=False):
+ ctx = Context(recipient.context)
+
+ if test:
+ contact = Contact(email=recipient.email, key='test')
+ else:
+ # TODO: actually, we should just use Contacts instead of recipients.
+ contact = Contact.objects.get(email=recipient.email)
+
+ ctx['contact'] = contact
+
+ subject = Template(self.subject).render(ctx)
+
+ if test:
+ subject = "[test] " + subject
+
+ body_template = '{% extends "messaging/email_body.html" %}{% block body %}' + self.body + '{% endblock %}'
+
+ body = Template(body_template).render(ctx)