email sponsor tickets one by one
This commit is contained in:
parent
38b7cae7d7
commit
7f95f41055
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue