forked from beba/foerderbarometer
added attachment helper
This commit is contained in:
parent
c751a9fc37
commit
7365218adb
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue