Navigation Menu

Skip to content

Commit

Permalink
Reverse order of premail and render operations to render email templa…
Browse files Browse the repository at this point in the history
…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 committed Jul 12, 2011
1 parent 21f74c4 commit 023ab05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
18 changes: 7 additions & 11 deletions nova/models.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions nova/views.py
Expand Up @@ -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.