more ticket information as data

This commit is contained in:
Clinton Roy 2019-09-24 18:36:40 +10:00 committed by Joel Addison
parent cf7e67a747
commit 9d37326953
2 changed files with 83 additions and 80 deletions

View file

@ -13,6 +13,7 @@ from symposion import proposals
class Command(BaseCommand): class Command(BaseCommand):
help = 'Populates the tickets and product inventory models' help = 'Populates the tickets and product inventory models'
count = 0
def add_arguments(self, parser): def add_arguments(self, parser):
pass pass
@ -286,70 +287,29 @@ class Command(BaseCommand):
order=10, order=10,
limit_per_user=1, limit_per_user=1,
) )
# Penguin dinner
self.penguin_adult = self.find_or_make( for t in settings.PENGUIN_DINNER.tickets:
self.find_or_make(
inv.Product, inv.Product,
("name", "category",), ("name", "category",),
category=self.penguin_dinner, category=self.penguin_dinner,
name=settings.PENGUIN_DINNER_ADULT.name, name=t.name,
description=settings.PENGUIN_DINNER_ADULT.description, description=t.description,
price=settings.PENGUIN_DINNER_ADULT.price, price=t.price,
reservation_duration=hours(1), reservation_duration=t.reservation,
order=10, order=t.order()
)
self.penguin_child = self.find_or_make(
inv.Product,
("name", "category",),
category=self.penguin_dinner,
name=settings.PENGUIN_DINNER_CHILD.name,
description=settings.PENGUIN_DINNER_CHILD.description,
price=settings.PENGUIN_DINNER_CHILD.price,
reservation_duration=hours(1),
order=20,
)
self.penguin_infant = self.find_or_make(
inv.Product,
("name", "category",),
category=self.penguin_dinner,
name=settings.PENGUIN_DINNER_INFANT.name,
description=settings.PENGUIN_DINNER_INFANT.description,
price=settings.PENGUIN_DINNER_INFANT.price,
reservation_duration=hours(1),
order=30,
) )
# Speakers' dinner for t in settings.SPEAKERS_DINNER.tickets:
self.find_or_make(
self.speakers_adult = self.find_or_make(
inv.Product, inv.Product,
("name", "category",), ("name", "category",),
category=self.speakers_dinner_ticket, category=self.speakers_dinner_ticket,
name=settings.SPEAKERS_DINNER_ADULT.name, name=t.name,
description=settings.SPEAKERS_DINNER_ADULT.description, description=t.description,
price=settings.SPEAKERS_DINNER_ADULT.price, price=t.price,
reservation_duration=hours(1), reservation_duration=t.reservation,
order=10, order=t.order()
)
self.speakers_child = self.find_or_make(
inv.Product,
("name", "category",),
category=self.speakers_dinner_ticket,
name=settings.SPEAKERS_DINNER_CHILD.name,
description=settings.SPEAKERS_DINNER_CHILD.description,
price=settings.SPEAKERS_DINNER_CHILD.price,
reservation_duration=hours(1),
order=20,
)
self.speaker_infant = self.find_or_make(
inv.Product,
("name", "category",),
category=self.speakers_dinner_ticket,
name=settings.SPEAKERS_DINNER_INFANT.name,
description=settings.SPEAKERS_DINNER_INFANT.description,
price=settings.SPEAKERS_DINNER_INFANT.price,
reservation_duration=hours(1),
order=30,
) )
# PDNS # PDNS
@ -826,6 +786,8 @@ class Command(BaseCommand):
]) ])
free_category(staff_t_shirts, self.t_shirt, quantity=5) free_category(staff_t_shirts, self.t_shirt, quantity=5)
print(f"{self.count} categories found/made")
def find_or_make(self, model, search_keys, **k): def find_or_make(self, model, search_keys, **k):
''' Either makes or finds an object of type _model_, with the given ''' Either makes or finds an object of type _model_, with the given
kwargs. kwargs.
@ -835,7 +797,7 @@ class Command(BaseCommand):
for an existing version in the database. The remaining arguments are for an existing version in the database. The remaining arguments are
only used when creating a new object. only used when creating a new object.
''' '''
self.count += 1
try: try:
keys = dict((key, k[key]) for key in search_keys) keys = dict((key, k[key]) for key in search_keys)
a = model.objects.get(**keys) a = model.objects.get(**keys)

View file

@ -7,7 +7,7 @@ import dj_database_url
import saml2 import saml2
import saml2.saml import saml2.saml
from datetime import date, datetime from datetime import date, datetime, timedelta
from dataclasses import dataclass from dataclasses import dataclass
@ -444,7 +444,15 @@ if DEV_MODE and DEV_MODE == "LAPTOP":
print("ENABLING LAPTOP MODE") print("ENABLING LAPTOP MODE")
from .devmode_settings import * from .devmode_settings import *
# Ticket information
class Category(object):
tickets = []
@classmethod
def order(cls, ticket) -> int:
return (cls.tickets.index(ticket) + 1) * 10
@dataclass(frozen=True) @dataclass(frozen=True)
class Ticket: class Ticket:
name: str name: str
@ -456,17 +464,39 @@ class Ticket:
@dataclass(frozen=True) @dataclass(frozen=True)
class PenguinDinnerTicket: class DinnerTicket:
name: str name: str
price: Decimal price: Decimal
description: str description: str
reservation: timedelta
cat: Category
def order(self):
return self.cat.order(self)
@dataclass(frozen=True) class PenguinDinnerTicket(DinnerTicket):
class SpeakersDinnerTicket: pass
name: str
price: Decimal
description: str class SpeakersDinnerTicket(DinnerTicket):
pass
class SpeakersDinnerCat(Category):
@classmethod
def create(cls, name: str, price: Decimal, description: str, reservation: timedelta) -> SpeakersDinnerTicket:
t = SpeakersDinnerTicket(name, price, description, reservation, cls)
cls.tickets.append(t)
return t
class PenguinDinnerCat(Category):
@classmethod
def create(cls, name: str, price: Decimal, description: str, reservation: timedelta) -> PenguinDinnerTicket:
t = PenguinDinnerTicket(name, price, description, reservation, cls)
cls.tickets.append(t)
return t
LCA_START = datetime(2020, 1, 13) LCA_START = datetime(2020, 1, 13)
@ -502,11 +532,22 @@ PENGUIN_DINNER_CHILD = PenguinDinnerTicket("Child", Decimal("50.00"),
PENGUIN_DINNER_INFANT = PenguinDinnerTicket("Infant", Decimal("0.0"), PENGUIN_DINNER_INFANT = PenguinDinnerTicket("Infant", Decimal("0.0"),
"Includes no food or beverage service.") "Includes no food or beverage service.")
SPEAKERS_DINNER_ADULT = SpeakersDinnerTicket("Adult", Decimal("100.00"), SPEAKERS_DINNER = SpeakersDinnerCat
"Includes an adult's meal and full beverage service.") PENGUIN_DINNER = PenguinDinnerCat
SPEAKERS_DINNER_CHILD = SpeakersDinnerTicket("Child", Decimal("60.00"),
SPEAKERS_DINNER_ADULT = SpeakersDinnerCat.create(
"Adult", Decimal("100.00"),
"Includes an adult's meal and full beverage service.",
timedelta(hours=1))
SPEAKERS_DINNER_CHILD = SpeakersDinnerCat.create(
"Child", Decimal("60.00"),
"Children 14 and under. " "Children 14 and under. "
"Includes a child's meal and soft drink service.") "Includes a child's meal and soft drink service.",
SPEAKERS_DINNER_INFANT = SpeakersDinnerTicket("Infant", Decimal("00.00"), timedelta(hours=1))
SPEAKERS_DINNER_INFANT = SpeakersDinnerCat.create(
"Infant", Decimal("00.00"),
"Infant must be seated in an adult's lap. " "Infant must be seated in an adult's lap. "
"No food or beverage service.") "No food or beverage service.",
timedelta(hours=1))