Add a command to generate sponsor tickets.
This commit is contained in:
parent
32f4ae13e3
commit
47bf0fcdbf
0
src/sponsors/management/__init__.py
Normal file
0
src/sponsors/management/__init__.py
Normal file
0
src/sponsors/management/commands/__init__.py
Normal file
0
src/sponsors/management/commands/__init__.py
Normal file
38
src/sponsors/management/commands/generate_sponsor_tickets.py
Normal file
38
src/sponsors/management/commands/generate_sponsor_tickets.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# 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 tickets.models import SponsorTicket, TicketType
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Creates sponsor tickets'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('camp_slug', type=str,)
|
||||
parser.add_argument('ticket_type_pk', 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):
|
||||
ticket_type = TicketType.objects.get(pk=options['ticket_type_pk'])
|
||||
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:
|
||||
self.output("# Generating tickets for {}:".format(sponsor))
|
||||
for _ in range(sponsor.tier.tickets):
|
||||
ticket = SponsorTicket(sponsor=sponsor, ticket_type=ticket_type)
|
||||
ticket.save()
|
||||
ticket.generate_pdf()
|
||||
self.output("- {}_ticket_{}.pdf".format(ticket.shortname, ticket.pk))
|
||||
else:
|
||||
self.output("{} is in tier {}, which has no tickets set.".format(sponsor, sponsor.tier))
|
23
src/sponsors/migrations/0008_auto_20180815_1119.py
Normal file
23
src/sponsors/migrations/0008_auto_20180815_1119.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.1 on 2018-08-15 09:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sponsors', '0007_auto_20180318_0906'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sponsor',
|
||||
name='tickets_generated',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sponsortier',
|
||||
name='tickets',
|
||||
field=models.IntegerField(blank=True, help_text='If set this is the number of tickets generated for a sponsor in this tier.', null=True),
|
||||
),
|
||||
]
|
|
@ -36,6 +36,8 @@ class Sponsor(CampRelatedModel):
|
|||
help_text="An URL to the sponsor."
|
||||
)
|
||||
|
||||
tickets_generated = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.name, self.tier.camp)
|
||||
|
||||
|
@ -70,5 +72,11 @@ class SponsorTier(CampRelatedModel):
|
|||
gold should have a lower value than silver."""
|
||||
)
|
||||
|
||||
tickets = models.IntegerField(
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="If set this is the number of tickets generated for a sponsor in this tier."
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.name, self.camp)
|
||||
|
|
Loading…
Reference in a new issue