Attach receipt PDF to "payment successful" email #96850

Closed
Anna Sirota wants to merge 5 commits from attach-pdf-to-email into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit 9c83663f1d - Show all commits

View File

@ -8,9 +8,10 @@ from django.dispatch import receiver
from django.template import loader
from django.urls import reverse
import looper.signals
import looper.models
from . import models, signals
from looper.pdf import PDFResponse
import looper.models
import looper.signals
log = logging.getLogger(__name__)
@ -137,14 +138,19 @@ def automatic_payment_performed(sender: looper.models.Order,
log.debug('Sending payment %r notification to %s', sender.status, email)
django.core.mail.send_mail(
subject,
message=email_body_txt,
html_message=email_body_html,
msg = django.core.mail.EmailMultiAlternatives(
subject=subject,
body=email_body_txt,
from_email=None, # just use the configured default From-address.
recipient_list=[email],
fail_silently=False,
to=[email],
)
file_data = b'TODO'
file_name = f'blender-development-fund-receipt-{sender.display_number}.pdf'
print(file_name)
file_data = PDFResponse().rendered_content
msg.attach(file_name, file_data, 'application/pdf')
msg.attach_alternative(email_body_html, 'text/html')
msg.send(fail_silently=False)
except Exception:
# Template rendering errors shouldn't interfere with the Looper clock, so
# catch all errors here.