diff --git a/input/utils/mail/__init__.py b/input/utils/mail/__init__.py index ec25b3f..32de5dd 100644 --- a/input/utils/mail/__init__.py +++ b/input/utils/mail/__init__.py @@ -4,13 +4,12 @@ from django.template.loader import get_template from input.models import Project -from .attachments import collect_attachment_paths, attach_files +from .attachments import collect_and_attach __all__ = [ 'build_email', 'send_email', - 'collect_attachment_paths', - 'attach_files', + 'collect_and_attach', 'send_applicant_decision_mail', 'send_staff_decision_mail', 'send_decision_mails', diff --git a/input/utils/mail/attachments.py b/input/utils/mail/attachments.py index 27d9cf5..0d6cfd1 100644 --- a/input/utils/mail/attachments.py +++ b/input/utils/mail/attachments.py @@ -92,3 +92,7 @@ def attach_files(message: EmailMultiAlternatives, files: list[Path]): with open(path, 'rb') as fp: message.attach(path.name, fp.read(), mime_type) + + +def collect_and_attach(email: EmailMultiAlternatives, recipient: str, type_code: str): + return attach_files(email, collect_attachment_paths(recipient, type_code)) diff --git a/input/views.py b/input/views.py index d92b2f9..10424b1 100755 --- a/input/views.py +++ b/input/views.py @@ -12,7 +12,7 @@ from django.views.generic import TemplateView from django.views.generic.edit import FormView from django.utils.html import strip_tags -from input.utils.mail import collect_attachment_paths, attach_files, build_email +from input.utils.mail import build_email, collect_and_attach from .forms import ( BaseApplicationForm, @@ -289,9 +289,8 @@ class ApplicationView(FormView): def send_email(self, kind, template_name, subject, recipient, context, *, fail_silently=False): email = build_email(template_name, context, subject, recipient) - applicant_files = collect_attachment_paths(kind, self.type_code) - attach_files(email, applicant_files) + collect_and_attach(email, kind, self.type_code) return email.send(fail_silently)