From bd2fd5338d8d96d96560dadef5ca8d730fe50c90 Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Sat, 8 Sep 2012 19:38:57 -0600 Subject: [PATCH] added DTL handling of email body --- symposion/proposals/models.py | 7 +++++++ symposion/reviews/models.py | 8 +------- symposion/reviews/views.py | 7 ++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/symposion/proposals/models.py b/symposion/proposals/models.py index 27f102dd..c71b025a 100644 --- a/symposion/proposals/models.py +++ b/symposion/proposals/models.py @@ -122,6 +122,13 @@ class ProposalBase(models.Model): yield self.speaker for speaker in self.additional_speakers.exclude(additionalspeaker__status=AdditionalSpeaker.SPEAKING_STATUS_DECLINED): yield speaker + + def notification_email_context(self): + return { + "title": self.title, + "speaker": self.speaker.name, + "kind": self.kind.name, + } reversion.register(ProposalBase) diff --git a/symposion/reviews/models.py b/symposion/reviews/models.py index ce3c3957..c03a1388 100644 --- a/symposion/reviews/models.py +++ b/symposion/reviews/models.py @@ -289,13 +289,7 @@ class NotificationTemplate(models.Model): label = models.CharField(max_length=100) from_address = models.EmailField() subject = models.CharField(max_length=100) - body = models.TextField( - help_text=( - "If the Body includes the string {{ proposal }} " - "then it will be replaced with the title of the proposal when the " - "email is sent." - ) - ) + body = models.TextField() class ResultNotification(models.Model): diff --git a/symposion/reviews/views.py b/symposion/reviews/views.py index 44c696f7..f22255e9 100644 --- a/symposion/reviews/views.py +++ b/symposion/reviews/views.py @@ -4,6 +4,7 @@ from django.core.mail import send_mass_mail from django.db.models import Q from django.http import HttpResponseBadRequest, HttpResponseNotAllowed from django.shortcuts import render, redirect, get_object_or_404 +from django.template import Context, Template from django.views.decorators.http import require_POST from django.contrib.auth.decorators import login_required @@ -472,7 +473,11 @@ def result_notification_send(request, section_slug, status): rn.to_address = proposal.speaker_email rn.from_address = request.POST["from_address"] rn.subject = request.POST["subject"] - rn.body = re.sub(r"{{\s*proposal\s*}}", proposal.title, request.POST["body"]) + rn.body = Template(request.POST["body"]).render( + Context({ + "proposal": proposal.notification_email_context() + }) + ) rn.save() emails.append(rn.email_args)