basic data transfer to mail template works now
This commit is contained in:
parent
f08ed17bb2
commit
552d56bdd2
|
@ -1 +1,3 @@
|
||||||
blurb
|
blurb
|
||||||
|
|
||||||
|
{{data}}
|
||||||
|
|
|
@ -13,12 +13,19 @@ from .settings import MAILS, EVA_MAIL
|
||||||
def success(request):
|
def success(request):
|
||||||
return HttpResponse("gut gemacht!")
|
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'
|
'send a mail to the given department with the nececcary notifications'
|
||||||
|
|
||||||
print(f'send mail to department {department}...')
|
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:
|
try:
|
||||||
mail_template = get_template(f'evapp/{department}_mail.txt')
|
mail_template = get_template(f'evapp/{department}_mail.txt')
|
||||||
send_mail(
|
send_mail(
|
||||||
|
@ -44,6 +51,6 @@ class EvaFormView(CreateView):
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
for dep in MAILS:
|
for dep in MAILS:
|
||||||
send_mail_to_department(dep)
|
send_mail_to_department(dep, form)
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
Loading…
Reference in New Issue