From 9d37326953b081697f978a715179450e957414d6 Mon Sep 17 00:00:00 2001 From: Clinton Roy Date: Tue, 24 Sep 2019 18:36:40 +1000 Subject: [PATCH] more ticket information as data --- .../management/commands/populate_inventory.py | 90 ++++++------------- pinaxcon/settings.py | 73 +++++++++++---- 2 files changed, 83 insertions(+), 80 deletions(-) diff --git a/pinaxcon/registrasion/management/commands/populate_inventory.py b/pinaxcon/registrasion/management/commands/populate_inventory.py index 8afbb2fd..c0877d34 100644 --- a/pinaxcon/registrasion/management/commands/populate_inventory.py +++ b/pinaxcon/registrasion/management/commands/populate_inventory.py @@ -13,6 +13,7 @@ from symposion import proposals class Command(BaseCommand): help = 'Populates the tickets and product inventory models' + count = 0 def add_arguments(self, parser): pass @@ -286,71 +287,30 @@ class Command(BaseCommand): order=10, limit_per_user=1, ) - # Penguin dinner - self.penguin_adult = self.find_or_make( - inv.Product, - ("name", "category",), - category=self.penguin_dinner, - name=settings.PENGUIN_DINNER_ADULT.name, - description=settings.PENGUIN_DINNER_ADULT.description, - price=settings.PENGUIN_DINNER_ADULT.price, - reservation_duration=hours(1), - order=10, - ) - 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, - ) + for t in settings.PENGUIN_DINNER.tickets: + self.find_or_make( + inv.Product, + ("name", "category",), + category=self.penguin_dinner, + name=t.name, + description=t.description, + price=t.price, + reservation_duration=t.reservation, + order=t.order() + ) - # Speakers' dinner - - self.speakers_adult = self.find_or_make( - inv.Product, - ("name", "category",), - category=self.speakers_dinner_ticket, - name=settings.SPEAKERS_DINNER_ADULT.name, - description=settings.SPEAKERS_DINNER_ADULT.description, - price=settings.SPEAKERS_DINNER_ADULT.price, - reservation_duration=hours(1), - order=10, - ) - 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, - ) + for t in settings.SPEAKERS_DINNER.tickets: + self.find_or_make( + inv.Product, + ("name", "category",), + category=self.speakers_dinner_ticket, + name=t.name, + description=t.description, + price=t.price, + reservation_duration=t.reservation, + order=t.order() + ) # PDNS @@ -826,6 +786,8 @@ class Command(BaseCommand): ]) 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): ''' Either makes or finds an object of type _model_, with the given kwargs. @@ -835,7 +797,7 @@ class Command(BaseCommand): for an existing version in the database. The remaining arguments are only used when creating a new object. ''' - + self.count += 1 try: keys = dict((key, k[key]) for key in search_keys) a = model.objects.get(**keys) diff --git a/pinaxcon/settings.py b/pinaxcon/settings.py index 167df088..48d551ed 100644 --- a/pinaxcon/settings.py +++ b/pinaxcon/settings.py @@ -7,7 +7,7 @@ import dj_database_url import saml2 import saml2.saml -from datetime import date, datetime +from datetime import date, datetime, timedelta from dataclasses import dataclass @@ -444,7 +444,15 @@ if DEV_MODE and DEV_MODE == "LAPTOP": print("ENABLING LAPTOP MODE") 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) class Ticket: name: str @@ -456,17 +464,39 @@ class Ticket: @dataclass(frozen=True) -class PenguinDinnerTicket: +class DinnerTicket: name: str price: Decimal description: str + reservation: timedelta + cat: Category + + def order(self): + return self.cat.order(self) -@dataclass(frozen=True) -class SpeakersDinnerTicket: - name: str - price: Decimal - description: str +class PenguinDinnerTicket(DinnerTicket): + pass + + +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) @@ -502,11 +532,22 @@ PENGUIN_DINNER_CHILD = PenguinDinnerTicket("Child", Decimal("50.00"), PENGUIN_DINNER_INFANT = PenguinDinnerTicket("Infant", Decimal("0.0"), "Includes no food or beverage service.") -SPEAKERS_DINNER_ADULT = SpeakersDinnerTicket("Adult", Decimal("100.00"), - "Includes an adult's meal and full beverage service.") -SPEAKERS_DINNER_CHILD = SpeakersDinnerTicket("Child", Decimal("60.00"), - "Children 14 and under. " - "Includes a child's meal and soft drink service.") -SPEAKERS_DINNER_INFANT = SpeakersDinnerTicket("Infant", Decimal("00.00"), - "Infant must be seated in an adult's lap. " - "No food or beverage service.") +SPEAKERS_DINNER = SpeakersDinnerCat +PENGUIN_DINNER = PenguinDinnerCat + +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. " + "Includes a child's meal and soft drink service.", + timedelta(hours=1)) + +SPEAKERS_DINNER_INFANT = SpeakersDinnerCat.create( + "Infant", Decimal("00.00"), + "Infant must be seated in an adult's lap. " + "No food or beverage service.", + timedelta(hours=1))