bornhack-website/src/sponsors/email.py

37 lines
1.0 KiB
Python
Raw Normal View History

2019-08-08 08:55:38 +00:00
import logging
import os
2019-08-08 08:55:38 +00:00
from django.conf import settings
from teams.models import Team
from utils.email import add_outgoing_email
2019-08-08 08:55:38 +00:00
logger = logging.getLogger("bornhack.%s" % __name__)
2020-02-07 17:46:34 +00:00
2019-08-08 08:44:37 +00:00
def add_sponsorticket_email(ticket):
# put formatdict together
formatdict = {
2019-08-08 08:44:37 +00:00
"ticket": ticket,
}
2019-08-08 09:53:46 +00:00
subject = "%s %s Sponsor Ticket %s" % (
2019-08-08 08:44:37 +00:00
ticket.sponsor.camp.title,
2019-08-08 09:53:46 +00:00
ticket.sponsor.name,
2019-08-08 08:44:37 +00:00
ticket.uuid,
)
2019-08-08 08:44:37 +00:00
filename = "sponsor_ticket_{}.pdf".format(ticket.pk)
2019-08-08 09:21:53 +00:00
with open(os.path.join(settings.PDF_ARCHIVE_PATH, filename), "rb") as f:
2019-08-08 08:44:37 +00:00
# add email to outgoing email queue
return add_outgoing_email(
responsible_team=Team.objects.get(camp=ticket.sponsor.camp, name="Sponsor"),
2019-08-08 08:44:37 +00:00
text_template="emails/sponsorticket_email.txt",
html_template="emails/sponsorticket_email.html",
2019-08-08 08:55:38 +00:00
to_recipients=ticket.sponsor.ticket_email,
2019-08-08 08:44:37 +00:00
formatdict=formatdict,
subject=subject,
attachment=f.read(),
2019-08-08 08:44:37 +00:00
attachment_filename=filename,
)