compute email's text body once (#16479)

This commit is contained in:
Serghei Mihai 2017-05-24 14:53:11 +02:00
parent 23c19695b1
commit 4d7874a5bf
1 changed files with 4 additions and 3 deletions

View File

@ -30,7 +30,7 @@ from django.core.urlresolvers import reverse
from django.core import signing
UNSUBSCRIBE_LINK_PLACEHOLDER = '##UNSUBSCRIBE_LINK_PLACEHOLDER##'
UNSUBSCRIBE_LINK_PLACEHOLDER = '%%UNSUBSCRIBE_LINK_PLACEHOLDER%%'
def transform_image_src(src, **kwargs):
@ -52,6 +52,8 @@ def send_email(title, content, destinations, category_id):
message.transformer.load_and_transform(images_inline=True)
message.transformer.save()
orig_html = message.html
handler.body_width = 0
orig_text = handler.handle(message.html)
for dest in destinations:
unsubscribe_token = signing.dumps({'category': category_id,
@ -59,9 +61,8 @@ def send_email(title, content, destinations, category_id):
unsubscribe_link = urlparse.urljoin(settings.SITE_BASE_URL, reverse(
'unsubscribe', kwargs={'unsubscription_token': unsubscribe_token}))
message.html = orig_html.replace(UNSUBSCRIBE_LINK_PLACEHOLDER, unsubscribe_link)
message.text = orig_text.replace(UNSUBSCRIBE_LINK_PLACEHOLDER, unsubscribe_link)
handler.body_width = 0
message.text = handler.handle(message.html)
sent = message.send(to=dest)
if sent:
total_sent += 1