Better programmatic email generation

Allow different content for HTML vs text
Automatically strip/tidy up text output
This commit is contained in:
Yingtong Li 2020-05-10 22:32:49 +10:00
parent fc1bb22dc4
commit 62119cc83c
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -87,10 +87,12 @@ class Emailer:
def render_mail(self, template_loc, params={}): def render_mail(self, template_loc, params={}):
params['baseurl'] = 'https://' + settings.ALLOWED_HOSTS[0] params['baseurl'] = 'https://' + settings.ALLOWED_HOSTS[0]
params['format'] = 'txt'
template = loader.get_template(template_loc) template = loader.get_template(template_loc)
content_txt = template.render(params) content_txt = template.render(params).strip().replace('\\*', '*')
content_markdown = self.markdown(content_txt) params['format'] = 'markdown'
content_markdown = self.markdown(template.render(params))
content_html = self.template.render({'email_content': Markup(content_markdown)}) content_html = self.template.render({'email_content': Markup(content_markdown)})
content_html = premailer.Premailer(content_html, cssutils_logging_level=logging.ERROR, strip_important=False).transform() content_html = premailer.Premailer(content_html, cssutils_logging_level=logging.ERROR, strip_important=False).transform()