diff --git a/src/sponsors/email.py b/src/sponsors/email.py index db0a8537..df23da42 100644 --- a/src/sponsors/email.py +++ b/src/sponsors/email.py @@ -1,25 +1,27 @@ from utils.email import add_outgoing_email -def add_sponsorticket_email(sponsor): +def add_sponsorticket_email(ticket): # put formatdict together formatdict = { - "sponsor": sponsor, + "ticket": ticket, } - subject = "BornHack %s Sponsor Tickets" % sponsor.camp.title - attachments = [] - for ticket in sponsor.sponsorticket_set.all(): - path = "sponsor_ticket_%s" % ticket.uuid - attachments.append() - - # add email to outgoing email queue - return add_outgoing_email( - text_template="emails/sponsorticket_email.txt", - html_template="emails/sponsorticket_email.html", - to_recipients=sponsor.ticket_email, - formatdict=formatdict, - subject=subject, - attachments=attachments + subject = "BornHack %s Sponsor Ticket %s" % ( + ticket.sponsor.camp.title, + ticket.uuid, ) + 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 + return add_outgoing_email( + text_template="emails/sponsorticket_email.txt", + html_template="emails/sponsorticket_email.html", + to_recipients=sponsor.ticket_email, + formatdict=formatdict, + subject=subject, + attachment=f.read(), + attachment_filename=filename, + ) + diff --git a/src/sponsors/management/commands/email_sponsor_tickets.py b/src/sponsors/management/commands/email_sponsor_tickets.py index 4b80d4d8..52832ab8 100644 --- a/src/sponsors/management/commands/email_sponsor_tickets.py +++ b/src/sponsors/management/commands/email_sponsor_tickets.py @@ -31,12 +31,14 @@ class Command(BaseCommand): sponsor.ticket_ready and not sponsor.tickets_sent ): - self.output("# Generating outgoing email to send tickets for {}:".format(sponsor)) - # send the email - if add_sponsorticket_email(sponsor=sponsor): - logger.info("OK: email to %s added" % sponsor) - sponsor.tickets_sent = True - sponsor.save() - else: - logger.error("Unable to send sponsor ticket email to %s" % sponsor) + self.output("# Generating outgoing emails to send tickets for {}:".format(sponsor)) + for ticket in sponsor.sponsorticket_set.all(): + # send the email + if add_sponsorticket_email(ticket=ticket): + logger.info("OK: email to %s added" % sponsor) + else: + logger.error("Unable to send sponsor ticket email to %s" % sponsor) + + sponsor.tickets_sent = True + sponsor.save() diff --git a/src/sponsors/templates/emails/sponsorticket_email.html b/src/sponsors/templates/emails/sponsorticket_email.html index 5eeca3bc..3f97ad7f 100644 --- a/src/sponsors/templates/emails/sponsorticket_email.html +++ b/src/sponsors/templates/emails/sponsorticket_email.html @@ -1,6 +1,6 @@ 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! :)

Best regards,
diff --git a/src/sponsors/templates/emails/sponsorticket_email.txt b/src/sponsors/templates/emails/sponsorticket_email.txt index 8b2882db..4f29bd38 100644 --- a/src/sponsors/templates/emails/sponsorticket_email.txt +++ b/src/sponsors/templates/emails/sponsorticket_email.txt @@ -1,6 +1,6 @@ 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! :) Best regards,