added DTL handling of email body
This commit is contained in:
parent
ecfabd5b70
commit
bd2fd5338d
3 changed files with 14 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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 <b>Body</b> includes the string <code>{{ proposal }}</code> "
|
||||
"then it will be replaced with the title of the proposal when the "
|
||||
"email is sent."
|
||||
)
|
||||
)
|
||||
body = models.TextField()
|
||||
|
||||
|
||||
class ResultNotification(models.Model):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue