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
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()
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",
@ -20,6 +21,7 @@ def add_sponsorticket_email(sponsor):
to_recipients=sponsor.ticket_email,
formatdict=formatdict,
subject=subject,
attachments=attachments
attachment=f.read(),
attachment_filename=filename,
)

View file

@ -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))
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(sponsor=sponsor):
if add_sponsorticket_email(ticket=ticket):
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)
sponsor.tickets_sent = True
sponsor.save()

View file

@ -1,6 +1,6 @@
Hello!<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>
<br>
Best regards,<br>

View file

@ -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,