Esempio n. 1
0
def product_view(view_id):
    view = ProductView.query.get_or_404(view_id)

    form = ProductViewForm(obj=view)
    if request.method != 'POST':
        # Empty form - populate pvps
        for pvp in view.product_view_products:
            form.pvps.append_entry()
            f = form.pvps[-1]
            f.product_id.data = pvp.product_id

            f.order.data = pvp.order

    pvp_dict = {pvp.product_id: pvp for pvp in view.product_view_products}
    for f in form.pvps:
        pvp = pvp_dict[f.product_id.data]
        pvp._field = f

    if form.validate_on_submit():
        if form.update.data:
            view.name = form.name.data
            view.type = form.type.data
            view.token = form.token.data

            for f in form.pvps:
                pvp_dict[f.product_id.data].order = f.order.data

        else:
            ProductViewProduct()
            pass

        db.session.commit()

    return render_template('admin/products/view-edit.html', view=view, form=form)
Esempio n. 2
0
def product_view_add(view_id, group_id=None, product_id=None):
    view = ProductView.query.get_or_404(view_id)
    form = AddProductViewProductForm()

    root_groups = (ProductGroup.query.filter_by(parent_id=None).order_by(
        ProductGroup.id).all())

    if product_id is not None:
        product = Product.query.get(product_id)
    else:
        product = None
        del form.add_product

    if group_id is not None:
        group = ProductGroup.query.get(group_id)
    else:
        group = None
        del form.add_all_products

    if form.validate_on_submit():
        if form.add_all_products.data:
            for product in group.products:
                ProductViewProduct(view, product)
            db.session.commit()

        elif form.add_product.data:
            ProductViewProduct(view, product)
            db.session.commit()

        return redirect(url_for(".product_view", view_id=view.id))

    return render_template(
        "admin/products/view-add-products.html",
        view=view,
        form=form,
        root_groups=root_groups,
        add_group=group,
        add_product=product,
    )
Esempio n. 3
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()
Esempio n. 4
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()