From 552d56bdd2a2eb902c19c00ee3bd85f5359bbebe Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Wed, 6 Jan 2021 11:20:11 +0100 Subject: [PATCH] basic data transfer to mail template works now --- evapp/templates/evapp/IT_mail.txt | 2 ++ evapp/views.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/evapp/templates/evapp/IT_mail.txt b/evapp/templates/evapp/IT_mail.txt index 8a51db6..e529bd4 100644 --- a/evapp/templates/evapp/IT_mail.txt +++ b/evapp/templates/evapp/IT_mail.txt @@ -1 +1,3 @@ blurb + +{{data}} diff --git a/evapp/views.py b/evapp/views.py index 07d5a30..98da803 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -13,12 +13,19 @@ from .settings import MAILS, EVA_MAIL def success(request): return HttpResponse("gut gemacht!") -def send_mail_to_department(department): +def send_mail_to_department(department, form): 'send a mail to the given department with the nececcary notifications' print(f'send mail to department {department}...') - context = {} + model = form.save() + context = {'data': {}} + + # add all relevant fields of the form to the template context + data = MAILS[department]['DATA'] + for key in data: + context['data'][key] = form.cleaned_data[key] + try: mail_template = get_template(f'evapp/{department}_mail.txt') send_mail( @@ -44,6 +51,6 @@ class EvaFormView(CreateView): def form_valid(self, form): for dep in MAILS: - send_mail_to_department(dep) + send_mail_to_department(dep, form) return super().form_valid(form)