Refactors to be a bit less obtuse

This commit is contained in:
Christopher Neugebauer 2016-08-21 15:31:09 +10:00 committed by Scott Bragg
parent d54d47487e
commit 96683b6d7d

View file

@ -8,27 +8,28 @@ from django.utils.html import strip_tags
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
def sender(template_prefix): class Sender(object):
''' Creates a function called `send_email` ''' ''' Class for sending e-mails under a templete prefix. '''
def send_email(to, kind, **kwargs): def __init__(self, template_prefix):
self.template_prefix = template_prefix
def send_email(self, to, kind, **kwargs):
''' Sends an e-mail to the given address. ''' Sends an e-mail to the given address.
to: The address to: The address
kind: the ID for an e-mail kind; it should point to a subdirectory of kind: the ID for an e-mail kind; it should point to a subdirectory of
%(template_prefix)s containing subject.txt and message.html, which self.template_prefix containing subject.txt and message.html, which
are django templates for the subject and HTML message respectively. are django templates for the subject and HTML message respectively.
context: a context for rendering the e-mail. context: a context for rendering the e-mail.
''' % {"template_prefix": template_prefix} '''
return __send_email__(template_prefix, to, kind, **kwargs) return __send_email__(self.template_prefix, to, kind, **kwargs)
return send_email
send_email = sender("symposion/emails") send_email = Sender("symposion/emails").send_email
def __send_email__(template_prefix, to, kind, **kwargs): def __send_email__(template_prefix, to, kind, **kwargs):