diff --git a/input/views.py b/input/views.py index 3eb4bc6..4bd5c3a 100755 --- a/input/views.py +++ b/input/views.py @@ -11,6 +11,8 @@ from django.conf import settings from django.contrib.auth.decorators import login_required from django.views.generic import TemplateView from django.views.generic.edit import FormView +from django.utils.html import strip_tags +from input.mail_attachments import collect_attachment_paths, attach_files from .forms import ( BaseApplicationForm, @@ -252,18 +254,32 @@ class ApplicationView(FormView): txt1 = get_template('input/ifg_volunteer_mail.txt').render(context) html1 = get_template('input/ifg_volunteer_mail.html').render(context) msg1 = EmailMultiAlternatives( - 'Formular ausgefüllt', txt1, settings.IF_EMAIL, [data['email']] + 'Deine Förderanfrage bei Wikimedia Deutschland', txt1, settings.IF_EMAIL, [data['email']] ) msg1.attach_alternative(html1, 'text/html') + applicant_files = collect_attachment_paths(kind='applicant', choice=self.type_code) + attach_files(msg1, applicant_files) msg1.send() - + type_label_html = TYPE_CHOICES.get(self.type_code, self.type_code) + type_label = strip_tags(str(type_label_html)) # Mail to IF txt2 = get_template('input/if_mail.txt').render(context) html2 = get_template('input/if_mail.html').render(context) + applicant_name = ( + getattr(modell, 'username', None) + or data.get('username') + or getattr(modell, 'realname', None) + or data.get('realname') + or getattr(modell, 'email', None) + or data.get('email') + or 'Unbekannt' + ) msg2 = EmailMultiAlternatives( - 'Formular ausgefüllt', txt2, settings.IF_EMAIL, [settings.IF_EMAIL] + f'Anfrage {type_label} von {applicant_name}', txt2, settings.IF_EMAIL, [settings.IF_EMAIL] ) msg2.attach_alternative(html2, 'text/html') + staff_files = collect_attachment_paths(kind='staff', choice=self.type_code) + attach_files(msg2, staff_files) msg2.send() except BadHeaderError: