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)