added DTL handling of email body
This commit is contained in:
parent
ecfabd5b70
commit
bd2fd5338d
3 changed files with 14 additions and 8 deletions
|
@ -123,6 +123,13 @@ class ProposalBase(models.Model):
|
||||||
for speaker in self.additional_speakers.exclude(additionalspeaker__status=AdditionalSpeaker.SPEAKING_STATUS_DECLINED):
|
for speaker in self.additional_speakers.exclude(additionalspeaker__status=AdditionalSpeaker.SPEAKING_STATUS_DECLINED):
|
||||||
yield speaker
|
yield speaker
|
||||||
|
|
||||||
|
def notification_email_context(self):
|
||||||
|
return {
|
||||||
|
"title": self.title,
|
||||||
|
"speaker": self.speaker.name,
|
||||||
|
"kind": self.kind.name,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
reversion.register(ProposalBase)
|
reversion.register(ProposalBase)
|
||||||
|
|
||||||
|
|
|
@ -289,13 +289,7 @@ class NotificationTemplate(models.Model):
|
||||||
label = models.CharField(max_length=100)
|
label = models.CharField(max_length=100)
|
||||||
from_address = models.EmailField()
|
from_address = models.EmailField()
|
||||||
subject = models.CharField(max_length=100)
|
subject = models.CharField(max_length=100)
|
||||||
body = models.TextField(
|
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."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ResultNotification(models.Model):
|
class ResultNotification(models.Model):
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.core.mail import send_mass_mail
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.http import HttpResponseBadRequest, HttpResponseNotAllowed
|
from django.http import HttpResponseBadRequest, HttpResponseNotAllowed
|
||||||
from django.shortcuts import render, redirect, get_object_or_404
|
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.views.decorators.http import require_POST
|
||||||
|
|
||||||
from django.contrib.auth.decorators import login_required
|
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.to_address = proposal.speaker_email
|
||||||
rn.from_address = request.POST["from_address"]
|
rn.from_address = request.POST["from_address"]
|
||||||
rn.subject = request.POST["subject"]
|
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()
|
rn.save()
|
||||||
emails.append(rn.email_args)
|
emails.append(rn.email_args)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue