Permalink
Browse files

Reverse order of premail and render operations to render email templa…

…tes before they are premailed. This allows you to use the 'include' template tag to inject markup into your newsletters. This change removes the ability to render a unique template per subscriber. That functionality should eventually be added back in with a future patch.
  • Loading branch information...
Tristan Waddington
Tristan Waddington committed Jul 12, 2011
1 parent 21f74c4 commit 023ab05d9a0283f15765723e0054e479a4242635
Showing with 10 additions and 13 deletions.
  1. +7 −11 nova/models.py
  2. +3 −2 nova/views.py
View
@@ -253,8 +253,9 @@ def save(self, *args, **kwargs):
super(NewsletterIssue, self).save(*args, **kwargs)
if self.template:
- html_template, _ = self.premail(track=self.track, plaintext=False)
- self.rendered_template = self.render(template=html_template)
+ html_template, _ = self.premail(track=self.track, plaintext=False,
+ template=self.render())
+ self.rendered_template = html_template
super(NewsletterIssue, self).save()
def premailer(self, template, plaintext=False):
@@ -360,7 +361,7 @@ def send(self, subject=None, email_addresses=None, extra_headers=None, mark_as_s
subject = self.subject
headers = {
- 'Reply-To': self.newsletter.reply_to_email,
+ 'Reply-To': self.newsletter.reply_to_email,
}
# Set any extra headers
@@ -376,16 +377,11 @@ def send(self, subject=None, email_addresses=None, extra_headers=None, mark_as_s
self.sent_at = datetime.now()
self.save()
- # Premail template
- html_template, plaintext_template = self.premail(track=self.track)
+ # Render and Premail template
+ rendered_html_template, rendered_plaintext_template = self.premail(track=self.track,
+ template=self.render())
for send_to in email_addresses:
- # Render the newsletter for this subscriber
- rendered_html_template = self.render(template=html_template,
- extra_context={'email': send_to})
- rendered_plaintext_template = self.render(template=plaintext_template,
- extra_context={'email': send_to})
-
# Send multipart message
send_multipart_mail(subject,
txt_body=rendered_plaintext_template,
View
@@ -187,5 +187,6 @@ def preview(request, newsletter_issue_id):
if subscribers.count() > 0:
email = subscribers[0]
- premailed_template, _ = issue.premail(track=issue.track, plaintext=False)
- return HttpResponse(issue.render(template=premailed_template, extra_context={'email':email}))
+ premailed_template, _ = issue.premail(track=issue.track, plaintext=False,
+ template=issue.render())
+ return HttpResponse(premailed_template)

0 comments on commit 023ab05

Please sign in to comment.