Commit 6b00be8d authored by fred's avatar fred

use templates to render newsletter

parent 871b42b8
......@@ -14,9 +14,11 @@ import html2text
from django.db import models
from django.core.urlresolvers import reverse
from django.template import loader, Context
from django.template import loader, Context
from django.template.loader import render_to_string
from django.conf import settings
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
......@@ -81,12 +83,13 @@ class Newsletter(models.Model):
h2t = html2text.HTML2Text()
h2t.unicode_snob = True
html = self.text.encode('utf-8')
if settings.NEWSLETTER_STYLE:
html += '''\n<style type="text/css">\n%s\n</style>''' % settings.NEWSLETTER_STYLE
context = {
'text_part': mark_safe(h2t.handle(self.text)),
'html_part': mark_safe(self.text),
}
part1 = MIMEText(h2t.handle(self.text).encode('utf-8'), 'plain', _charset='utf-8')
part2 = MIMEText(html, 'html', _charset='utf-8')
part1 = MIMEText(render_to_string('newsletter/email_body.txt', context), 'plain', _charset='utf-8')
part2 = MIMEText(render_to_string('newsletter/email_body.html', context), 'html', _charset='utf-8')
msg.attach(part1)
msg.attach(part2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment