add management command to email sponsor tickets
This commit is contained in:
parent
99977759ee
commit
ac19a6db4b
|
@ -5,7 +5,7 @@ from .models import Sponsor, SponsorTier
|
||||||
|
|
||||||
@admin.register(Sponsor)
|
@admin.register(Sponsor)
|
||||||
class SponsorAdmin(admin.ModelAdmin):
|
class SponsorAdmin(admin.ModelAdmin):
|
||||||
list_display = ("name", "tier")
|
list_display = ("name", "tier", "ticket_email", "ticket_ready", "tickets_sent")
|
||||||
list_filter = ("tier__camp",)
|
list_filter = ("tier__camp",)
|
||||||
|
|
||||||
|
|
||||||
|
|
25
src/sponsors/email.py
Normal file
25
src/sponsors/email.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from utils.email import add_outgoing_email
|
||||||
|
|
||||||
|
|
||||||
|
def add_sponsorticket_email(sponsor):
|
||||||
|
# put formatdict together
|
||||||
|
formatdict = {
|
||||||
|
"sponsor": sponsor,
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
36
src/sponsors/management/commands/email_sponsor_tickets.py
Normal file
36
src/sponsors/management/commands/email_sponsor_tickets.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# coding: utf-8
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from camps.models import Camp
|
||||||
|
from sponsors.models import Sponsor
|
||||||
|
from sponsors.email import add_sponsorticket_email
|
||||||
|
from tickets.models import SponsorTicket, TicketType
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Emails sponsor tickets"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument("camp_slug", type=str)
|
||||||
|
|
||||||
|
def output(self, message):
|
||||||
|
self.stdout.write(
|
||||||
|
"{}: {}".format(timezone.now().strftime("%Y-%m-%d %H:%M:%S"), message)
|
||||||
|
)
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
camp = Camp.objects.get(slug=options["camp_slug"])
|
||||||
|
sponsors = Sponsor.objects.filter(tier__camp=camp, tickets_generated=False)
|
||||||
|
|
||||||
|
for sponsor in sponsors:
|
||||||
|
if sponsor.tier.tickets and sponsor.ticket_email and 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)
|
||||||
|
|
28
src/sponsors/migrations/0012_auto_20190807_2229.py
Normal file
28
src/sponsors/migrations/0012_auto_20190807_2229.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# Generated by Django 2.2.3 on 2019-08-07 20:29
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('sponsors', '0011_auto_20181118_1513'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sponsor',
|
||||||
|
name='ticket_email',
|
||||||
|
field=models.EmailField(blank=True, help_text='The email to send the tickets to', max_length=254, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sponsor',
|
||||||
|
name='ticket_ready',
|
||||||
|
field=models.BooleanField(default=False, help_text='Check when we are ready to send tickets to this sponsor.'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='sponsor',
|
||||||
|
name='tickets_sent',
|
||||||
|
field=models.BooleanField(default=False, help_text='True when the tickets have been emailed to the sponsor'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -23,6 +23,12 @@ class Sponsor(CampRelatedModel):
|
||||||
|
|
||||||
tickets_generated = models.BooleanField(default=False)
|
tickets_generated = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
ticket_email = models.EmailField(null=True, blank=True, help_text="The email to send the tickets to")
|
||||||
|
|
||||||
|
ticket_ready = models.BooleanField(default=False, help_text="Check when we are ready to send tickets to this sponsor.")
|
||||||
|
|
||||||
|
tickets_sent = models.BooleanField(default=False, help_text="True when the tickets have been emailed to the sponsor")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} ({})".format(self.name, self.tier.camp)
|
return "{} ({})".format(self.name, self.tier.camp)
|
||||||
|
|
||||||
|
|
11
src/sponsors/templates/emails/sponsorticket_email.html
Normal file
11
src/sponsors/templates/emails/sponsorticket_email.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
Hello!<br>
|
||||||
|
<br>
|
||||||
|
This email contains the {{ sponsor.name }} sponsor tickets for {{ sponsor.camp.title }}<br>
|
||||||
|
Thank you for helping out! :)<br>
|
||||||
|
<br>
|
||||||
|
Best regards,<br>
|
||||||
|
<br>
|
||||||
|
BornHack<br>
|
||||||
|
<br>
|
||||||
|
(This email is automatically generated)<br>
|
||||||
|
<br>
|
11
src/sponsors/templates/emails/sponsorticket_email.txt
Normal file
11
src/sponsors/templates/emails/sponsorticket_email.txt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
Hello!
|
||||||
|
|
||||||
|
This email contains the {{ sponsor.name }} sponsor tickets for {{ sponsor.camp.title }}
|
||||||
|
Thank you for helping out! :)
|
||||||
|
|
||||||
|
Best regards,
|
||||||
|
|
||||||
|
BornHack
|
||||||
|
|
||||||
|
(This email is automatically generated)
|
||||||
|
|
Loading…
Reference in a new issue