示例#1
0
def create_product_groups():
    top_level_groups = [
        # name, capacity, expires
        ('admissions', None, 2500),
        ('parking', None, None),
        ('campervan', None, None),
        ('merchandise', None, None),
    ]
    for name, expires, capacity in top_level_groups:
        if ProductGroup.get_by_name(name):
            continue
        pg = ProductGroup(name=name, type=name, capacity_max=capacity, expires=expires)
        db.session.add(pg)

    db.session.flush()

    allocations = [
        # name, capacity
        ('vendors', 100),
        ('sponsors', 200),
        ('speakers', 100),
        ('general', 1800),
    ]

    admissions = ProductGroup.get_by_name('admissions')
    for name, capacity in allocations:
        if ProductGroup.get_by_name(name):
            continue
        ProductGroup(name=name, capacity_max=capacity, parent=admissions)

    view = ProductView.get_by_name('main')
    if not view:
        view = ProductView(name='main', type='tickets')
        db.session.add(view)

    db.session.flush()

    general = ProductGroup.get_by_name('general')

    products = [
        # name, display name, transferable, badge, capacity, description, (std cap, gbp eur), (early cap, gbp, eur), (late cap, gbp, eur)
        ('full', 'Full Camp Ticket', True, True, None, 'Full ticket',
            ((1500, 115, 135), (250, 105, 125), (None, 125, 145))
        ),
        ('full-s', 'Full Camp Ticket (Supporter)', True, True, None, 'Support this non-profit event by paying a bit more. All money will go towards making EMF more awesome.',
            ((None, 150, 180),)
        ),
        ('full-sg', 'Full Camp Ticket (Gold Supporter)', True, True, None, 'Support this non-profit event by paying a bit more. All money will go towards making EMF more awesome.',
            ((None, 200, 240),)
        ),
        ('u18', 'Under-18', True, False, 150, 'For visitors born after August 30th, 2000. All under-18s must be accompanied by an adult.',
            ((None, 55, 63),)
        ),
        ('u12', 'Under-12', True, False, 50, 'For children born after August 30th, 2006. All children must be accompanied by an adult.',
            ((None, 0, 0),)
        ),
    ]

    order = 0

    for name, display_name, has_xfer, has_badge, capacity, description, prices in products:
        if Product.get_by_name('general', name):
            continue
        product = Product(name=name, display_name=display_name, capacity_max=capacity,
                     description=description, parent=general,
                     attributes={'is_transferable': has_xfer,
                                 'has_badge': has_badge})

        for index, (price_cap, gbp, eur) in enumerate(prices):
            if len(prices) == 1 or index == 0:
                tier_name = name + '-std'
                active = True

            elif index == 1:
                tier_name = name + '-early-bird'
                active = False

            elif index == 2:
                tier_name = name + '-late'
                active = False

            if PriceTier.get_by_name('general', 'name', tier_name):
                continue

            pt = PriceTier(name=tier_name, capacity_max=price_cap, personal_limit=10, parent=product, active=active)
            Price(currency='GBP', price_int=gbp * 100, price_tier=pt)
            Price(currency='EUR', price_int=eur * 100, price_tier=pt)

        ProductViewProduct(view, product, order)
        order += 1

    db.session.flush()

    misc = [
        # name, display_name, cap, personal_limit, gbp, eur, description
        ('parking', 'Parking Ticket', 1700, 4, 15, 21, "We're trying to keep cars to a minimum. Please take public transport or car-share if you can."),
        ('campervan', 'Caravan/\u200cCampervan Ticket', 60, 2, 30, 42, "If you bring a caravan, you won't need a separate parking ticket for the towing car."),
    ]

    for name, display_name, cap, personal_limit, gbp, eur, description in misc:
        if Product.get_by_name(name, name):
            continue

        group = ProductGroup.get_by_name(name)
        product = Product(name=name, display_name=display_name, description=description, parent=group)
        pt = PriceTier(name=name, personal_limit=personal_limit, parent=product)
        db.session.add(pt)
        db.session.add(Price(currency='GBP', price_int=gbp * 100, price_tier=pt))
        db.session.add(Price(currency='EUR', price_int=eur * 100, price_tier=pt))

        ProductViewProduct(view, product, order)
        order += 1

    db.session.commit()
示例#2
0
def create_product_groups():
    top_level_groups = [
        # name, capacity, expires
        ('admissions', datetime(2018, 9,
                                3), app.config.get('MAXIMUM_ADMISSIONS')),
        ('parking', datetime(2018, 9, 3), None),
        ('campervan', datetime(2018, 9, 3), None),
        ('merchandise', datetime(2018, 8, 12), None),
    ]
    for name, expires, capacity in top_level_groups:
        if ProductGroup.get_by_name(name):
            continue
        pg = ProductGroup(name=name,
                          type=name,
                          capacity_max=capacity,
                          expires=expires)
        db.session.add(pg)

    db.session.flush()

    allocations = [
        # name, capacity
        ('vendors', 100),
        ('sponsors', 200),
        ('speakers', 100),
        ('general', 800),
    ]

    admissions = ProductGroup.get_by_name('admissions')
    for name, capacity in allocations:
        if ProductGroup.get_by_name(name):
            continue
        ProductGroup(name=name, capacity_max=capacity, parent=admissions)

    view = ProductView.get_by_name('main')
    if not view:
        view = ProductView(name='main', type='tickets')
        db.session.add(view)

    db.session.flush()

    general = ProductGroup.get_by_name('general')

    products = [
        # name, display name, transferable, badge, capacity, description, (std cap, gbp eur), (early cap, gbp, eur), (late cap, gbp, eur)
        ('full', 'Full Camp Ticket', True, True, None, 'Full ticket',
         ((1500, 115, 135), (250, 105, 125), (None, 125, 145))),
        ('full-s', 'Full Camp Ticket (Supporter)', True, True, None,
         'Support this non-profit event by paying a bit more. All money will go towards making EMF more awesome.',
         ((None, 150, 180), )),
        ('full-sg', 'Full Camp Ticket (Gold Supporter)', True, True, None,
         'Support this non-profit event by paying a bit more. All money will go towards making EMF more awesome.',
         ((None, 200, 240), )),
        ('u18', 'Under-18', True, False, 150,
         'For visitors born after August 30th, 2000. All under-18s must be accompanied by an adult.',
         ((None, 55, 63), )),
        ('u12', 'Under-12', True, False, 50,
         'For children born after August 30th, 2006. All children must be accompanied by an adult.',
         ((None, 0, 0), )),
    ]

    order = 0

    for name, display_name, has_xfer, has_badge, capacity, description, prices in products:
        if Product.get_by_name('general', name):
            continue
        product = Product(name=name,
                          display_name=display_name,
                          capacity_max=capacity,
                          description=description,
                          parent=general,
                          attributes={
                              'is_transferable': has_xfer,
                              'has_badge': has_badge
                          })

        for index, (price_cap, gbp, eur) in enumerate(prices):
            if len(prices) == 1 or index == 0:
                tier_name = name + '-std'
                active = True

            elif index == 1:
                tier_name = name + '-early-bird'
                active = False

            elif index == 2:
                tier_name = name + '-late'
                active = False

            if PriceTier.get_by_name('general', 'name', tier_name):
                continue

            pt = PriceTier(name=tier_name,
                           capacity_max=price_cap,
                           personal_limit=10,
                           parent=product,
                           active=active)
            Price(currency='GBP', price_int=gbp * 100, price_tier=pt)
            Price(currency='EUR', price_int=eur * 100, price_tier=pt)

        ProductViewProduct(view, product, order)
        order += 1

    db.session.flush()

    misc = [
        # name, display_name, cap, personal_limit, gbp, eur, description
        ('parking', 'Parking Ticket', 1700, 4, 15, 21,
         "We're trying to keep cars to a minimum. Please take public transport or car-share if you can."
         ),
        ('campervan', 'Caravan/\u200cCampervan Ticket', 60, 2, 30, 42,
         "If you bring a caravan, you won't need a separate parking ticket for the towing car."
         ),
    ]

    for name, display_name, cap, personal_limit, gbp, eur, description in misc:
        if Product.get_by_name(name, name):
            continue

        group = ProductGroup.get_by_name(name)
        product = Product(name=name,
                          display_name=display_name,
                          description=description,
                          parent=group)
        pt = PriceTier(name=name,
                       personal_limit=personal_limit,
                       parent=product)
        db.session.add(pt)
        db.session.add(
            Price(currency='GBP', price_int=gbp * 100, price_tier=pt))
        db.session.add(
            Price(currency='EUR', price_int=eur * 100, price_tier=pt))

        ProductViewProduct(view, product, order)
        order += 1

    db.session.commit()
示例#3
0
def create_product_groups():
    top_level_groups = [
        # name, capacity, expires
        ("admissions", None, 2500),
        ("parking", None, None),
        ("campervan", None, None),
        ("merchandise", None, None),
    ]
    for name, expires, capacity in top_level_groups:
        if ProductGroup.get_by_name(name):
            continue
        pg = ProductGroup(name=name,
                          type=name,
                          capacity_max=capacity,
                          expires=expires)
        db.session.add(pg)

    db.session.flush()

    allocations = [
        # name, capacity
        ("vendors", 100),
        ("sponsors", 200),
        ("speakers", 100),
        ("general", 1800),
    ]

    admissions = ProductGroup.get_by_name("admissions")
    for name, capacity in allocations:
        if ProductGroup.get_by_name(name):
            continue
        ProductGroup(name=name, capacity_max=capacity, parent=admissions)

    view = ProductView.get_by_name("main")
    if not view:
        view = ProductView(name="main", type="tickets")
        db.session.add(view)

    db.session.flush()

    general = ProductGroup.get_by_name("general")

    products = [
        # name, display name, transferable, badge, capacity, description, (std cap, gbp eur), (early cap, gbp, eur), (late cap, gbp, eur)
        (
            "full",
            "Full Camp Ticket",
            True,
            True,
            None,
            "Full ticket",
            ((1500, 115, 135), (250, 105, 125), (None, 125, 145)),
        ),
        (
            "full-s",
            "Full Camp Ticket (Supporter)",
            True,
            True,
            None,
            "Support this non-profit event by paying a bit more. All money will go towards making EMF more awesome.",
            ((None, 150, 180), ),
        ),
        (
            "full-sg",
            "Full Camp Ticket (Gold Supporter)",
            True,
            True,
            None,
            "Support this non-profit event by paying a bit more. All money will go towards making EMF more awesome.",
            ((None, 200, 240), ),
        ),
        (
            "u18",
            "Under-18",
            True,
            False,
            150,
            "For visitors born after August 30th, 2000. All under-18s must be accompanied by an adult.",
            ((None, 55, 63), ),
        ),
        (
            "u12",
            "Under-12",
            True,
            False,
            50,
            "For children born after August 30th, 2006. All children must be accompanied by an adult.",
            ((None, 0, 0), ),
        ),
    ]

    order = 0

    for (
            name,
            display_name,
            has_xfer,
            has_badge,
            capacity,
            description,
            prices,
    ) in products:
        if Product.get_by_name("general", name):
            continue
        product = Product(
            name=name,
            display_name=display_name,
            capacity_max=capacity,
            description=description,
            parent=general,
            attributes={
                "is_transferable": has_xfer,
                "has_badge": has_badge
            },
        )

        for index, (price_cap, gbp, eur) in enumerate(prices):
            if len(prices) == 1 or index == 0:
                tier_name = name + "-std"
                active = True

            elif index == 1:
                tier_name = name + "-early-bird"
                active = False

            elif index == 2:
                tier_name = name + "-late"
                active = False

            if PriceTier.get_by_name("general", "name", tier_name):
                continue

            pt = PriceTier(
                name=tier_name,
                capacity_max=price_cap,
                personal_limit=10,
                parent=product,
                active=active,
            )
            Price(currency="GBP", price_int=gbp * 100, price_tier=pt)
            Price(currency="EUR", price_int=eur * 100, price_tier=pt)

        ProductViewProduct(view, product, order)
        order += 1

    db.session.flush()

    misc = [
        # name, display_name, cap, personal_limit, gbp, eur, description
        (
            "parking",
            "Parking Ticket",
            1700,
            4,
            15,
            21,
            "We're trying to keep cars to a minimum. Please take public transport or car-share if you can.",
        ),
        (
            "campervan",
            "Caravan/\u200cCampervan Ticket",
            60,
            2,
            30,
            42,
            "If you bring a caravan, you won't need a separate parking ticket for the towing car.",
        ),
    ]

    for name, display_name, cap, personal_limit, gbp, eur, description in misc:
        if Product.get_by_name(name, name):
            continue

        group = ProductGroup.get_by_name(name)
        product = Product(name=name,
                          display_name=display_name,
                          description=description,
                          parent=group)
        pt = PriceTier(name=name,
                       personal_limit=personal_limit,
                       parent=product)
        db.session.add(pt)
        db.session.add(
            Price(currency="GBP", price_int=gbp * 100, price_tier=pt))
        db.session.add(
            Price(currency="EUR", price_int=eur * 100, price_tier=pt))

        ProductViewProduct(view, product, order)
        order += 1

    db.session.commit()