From 173e82684c1c9341b5ed9e035c1aa48578be678a Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 20 Nov 2014 02:54:45 -0400 Subject: [PATCH] Fix support for send document links and attachments --- mayan/apps/mailer/tasks.py | 10 ++++------ mayan/apps/mailer/views.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mayan/apps/mailer/tasks.py b/mayan/apps/mailer/tasks.py index 9e7b6d7ea3..42e60c9920 100644 --- a/mayan/apps/mailer/tasks.py +++ b/mayan/apps/mailer/tasks.py @@ -7,14 +7,12 @@ from mayan.celery import app @app.task(ignore_result=True) -def task_send_document(subject_text, body_text_content, sender, recipient, document_ids=None): +def task_send_document(subject_text, body_text_content, sender, recipient, document_id, as_attachment=False): email_msg = EmailMultiAlternatives(subject_text, body_text_content, sender, [recipient]) - if document_ids: - documents = [Document.objects.get(pk=document_id) for document_id in document_ids] - for document in documents: - descriptor = document.open() + if as_attachment: + document = Document.objects.get(pk=document_id) + with document.open() as descriptor: email_msg.attach(document.label, descriptor.read(), document.file_mimetype) - descriptor.close() email_msg.send() diff --git a/mayan/apps/mailer/views.py b/mayan/apps/mailer/views.py index 7b1ea306ee..17b68b7eb2 100644 --- a/mayan/apps/mailer/views.py +++ b/mayan/apps/mailer/views.py @@ -63,7 +63,7 @@ def send_document_link(request, document_id=None, document_id_list=None, as_atta subject_template = Template(form.cleaned_data['subject']) subject_text = strip_tags(subject_template.render(context)) - task_send_document.apply_async(args=(subject_text, body_text_content, request.user.email, form.cleaned_data['email']), kwargs={'document_ids': [document.pk for document in documents]}, queue='mailing') + task_send_document.apply_async(args=(subject_text, body_text_content, request.user.email, form.cleaned_data['email']), kwargs={'document_id': document.pk, 'as_attachment': as_attachment}, queue='mailing') # TODO: Pluralize messages.success(request, _('Successfully queued for delivery via email.'))