Added newsletter email template rendering

This commit is contained in:
Zakary Timson 2017-09-29 19:02:04 -04:00
parent f216f5fb49
commit 0885c9ae4f

View File

@ -3,6 +3,7 @@ from django.core import mail
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils import timezone from django.utils import timezone
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.template.loader import render_to_string
from OACPL import settings from OACPL import settings
from newsletters.models import Newsletter, Subscriber from newsletters.models import Newsletter, Subscriber
@ -18,7 +19,7 @@ class Command(BaseCommand):
print('Found %s subscribers' % len(subscribers)) print('Found %s subscribers' % len(subscribers))
for newsletter in newsletters: for newsletter in newsletters:
print('Sending newsletter: "$s"' % newsletter.subject) print('Sending newsletter: "$s"' % newsletter.subject)
mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=newsletter.body) mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=render_to_string('email.html', {'content', newsletter.body}))
newsletter.sent = True newsletter.sent = True
newsletter.save() newsletter.save()
print('Complete!') print('Complete!')