8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-06-18 08:38:09 +00:00

Move both send_mail utils to same file

This commit is contained in:
Jean-Romain Garnier 2020-04-19 21:15:07 +02:00 committed by Gabriel Detraz
parent cd097cd428
commit 6900c153d1
2 changed files with 17 additions and 19 deletions

View file

@ -23,9 +23,7 @@ import os
from django.template.loader import get_template
from django.core.mail import EmailMessage
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from smtplib import SMTPException
from re2o.mail_utils import send_mail_object
from .tex import create_pdf
from preferences.models import AssoOption, GeneralOption, CotisationsOption, Mandate
@ -46,20 +44,6 @@ def find_payment_method(payment):
return None
def send_mail(mail, request):
"""Wrapper for Django's EmailMessage.send which handles errors"""
try:
mail.send()
except (SMTPException, ConnectionError) as e:
if request:
messages.error(
request,
_("Failed to send email: %(error)s.") % {
"error": e,
},
)
def send_mail_invoice(invoice, request=None):
"""Creates the pdf of the invoice and sends it by email to the client"""
purchases_info = []
@ -108,7 +92,7 @@ def send_mail_invoice(invoice, request=None):
attachments=[("invoice.pdf", pdf, "application/pdf")],
)
send_mail(mail, request)
send_mail_object(mail, request)
def send_mail_voucher(invoice, request=None):
@ -145,4 +129,4 @@ def send_mail_voucher(invoice, request=None):
attachments=[("voucher.pdf", pdf, "application/pdf")],
)
send_mail(mail, request)
send_mail_object(mail, request)

View file

@ -43,3 +43,17 @@ def send_mail(request, *args, **kwargs):
"error": e,
},
)
def send_mail_object(mail, request):
"""Wrapper for Django's EmailMessage.send which handles errors"""
try:
mail.send()
except (SMTPException, ConnectionError) as e:
if request:
messages.error(
request,
_("Failed to send email: %(error)s.") % {
"error": e,
},
)