From dfc449f0de17ffd0937b8bd416e5a61f1ae87d87 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Thu, 8 Oct 2020 12:38:49 +0200 Subject: [PATCH] added mail to IF --- input/templates/input/if_mail.txt | 3 +++ input/views.py | 34 +++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 input/templates/input/if_mail.txt diff --git a/input/templates/input/if_mail.txt b/input/templates/input/if_mail.txt new file mode 100644 index 0000000..e5d9acb --- /dev/null +++ b/input/templates/input/if_mail.txt @@ -0,0 +1,3 @@ +Hallo IF, + +es gab einen neuen Antrag von {{data.realname}} diff --git a/input/views.py b/input/views.py index 93d4e40..48d5dfa 100644 --- a/input/views.py +++ b/input/views.py @@ -2,7 +2,7 @@ from django.shortcuts import render from django.forms import modelformset_factory from django.http import HttpResponse from formtools.wizard.views import CookieWizardView -from django.core.mail import send_mail +from django.core.mail import send_mail, BadHeaderError from django.conf import settings from django.template.loader import get_template from django.template import Context @@ -89,17 +89,29 @@ class ExternView(CookieWizardView): form.save() # we need to send the following mails here: - # - mail with entered data to the Volunteer - mail_template = get_template('input/ifg_volunteer_mail.txt') context = { 'data': data } - send_mail( - 'form filled', - mail_template.render(context), - settings.IF_EMAIL, - [form.email], - fail_silently=False, - ) - # - mail to IF with link to accept/decline + try: + # - mail with entered data to the Volunteer + mail_template = get_template('input/ifg_volunteer_mail.txt') + send_mail( + 'form filled', + mail_template.render(context), + settings.IF_EMAIL, + [form.email], + fail_silently=False, + ) + # - mail to IF with link to accept/decline + mail_template = get_template('input/if_mail.txt') + send_mail( + 'form filled', + mail_template.render(context), + settings.IF_EMAIL, + [settings.IF_EMAIL], + fail_silently=False, + ) + + except BadHeaderError: + return HttpResponse('Invalid header found.') return done(self.request) # return render(self.request, 'saved', {