email sponsor tickets one by one

This commit is contained in:
Thomas Steen Rasmussen 2019-08-08 10:44:37 +02:00
parent 38b7cae7d7
commit 7f95f41055
4 changed files with 30 additions and 26 deletions

View file

@ -1,18 +1,19 @@
from utils.email import add_outgoing_email from utils.email import add_outgoing_email
def add_sponsorticket_email(sponsor): def add_sponsorticket_email(ticket):
# put formatdict together # put formatdict together
formatdict = { formatdict = {
"sponsor": sponsor, "ticket": ticket,
} }
subject = "BornHack %s Sponsor Tickets" % sponsor.camp.title subject = "BornHack %s Sponsor Ticket %s" % (
attachments = [] ticket.sponsor.camp.title,
for ticket in sponsor.sponsorticket_set.all(): ticket.uuid,
path = "sponsor_ticket_%s" % ticket.uuid )
attachments.append()
filename = "sponsor_ticket_{}.pdf".format(ticket.pk)
with open(os.path.join(settings.PDF_ARCHIVE_PATH, filename)) as f:
# add email to outgoing email queue # add email to outgoing email queue
return add_outgoing_email( return add_outgoing_email(
text_template="emails/sponsorticket_email.txt", text_template="emails/sponsorticket_email.txt",
@ -20,6 +21,7 @@ def add_sponsorticket_email(sponsor):
to_recipients=sponsor.ticket_email, to_recipients=sponsor.ticket_email,
formatdict=formatdict, formatdict=formatdict,
subject=subject, subject=subject,
attachments=attachments attachment=f.read(),
attachment_filename=filename,
) )

View file

@ -31,12 +31,14 @@ class Command(BaseCommand):
sponsor.ticket_ready and sponsor.ticket_ready and
not sponsor.tickets_sent not sponsor.tickets_sent
): ):
self.output("# Generating outgoing email to send tickets for {}:".format(sponsor)) self.output("# Generating outgoing emails to send tickets for {}:".format(sponsor))
for ticket in sponsor.sponsorticket_set.all():
# send the email # send the email
if add_sponsorticket_email(sponsor=sponsor): if add_sponsorticket_email(ticket=ticket):
logger.info("OK: email to %s added" % sponsor) logger.info("OK: email to %s added" % sponsor)
sponsor.tickets_sent = True
sponsor.save()
else: else:
logger.error("Unable to send sponsor ticket email to %s" % sponsor) logger.error("Unable to send sponsor ticket email to %s" % sponsor)
sponsor.tickets_sent = True
sponsor.save()

View file

@ -1,6 +1,6 @@
Hello!<br> Hello!<br>
<br> <br>
This email contains the {{ sponsor.name }} sponsor tickets for {{ sponsor.camp.title }}<br> This email contains a {{ ticket.sponsor.name }} sponsor ticket for {{ ticket.sponsor.camp.title }}<br>
Thank you for helping out! :)<br> Thank you for helping out! :)<br>
<br> <br>
Best regards,<br> Best regards,<br>

View file

@ -1,6 +1,6 @@
Hello! Hello!
This email contains the {{ sponsor.name }} sponsor tickets for {{ sponsor.camp.title }} This email contains a {{ ticket.sponsor.name }} sponsor ticket for {{ ticket.sponsor.camp.title }}
Thank you for helping out! :) Thank you for helping out! :)
Best regards, Best regards,