basic data transfer to mail template works now
This commit is contained in:
parent
f08ed17bb2
commit
552d56bdd2
evapp
|
@ -1 +1,3 @@
|
|||
blurb
|
||||
|
||||
{{data}}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue