示例#1
0
def handle_edit_listing(prod_id):
    """ Updates both the parent and subset objects based on the edit form
        submitted in the route above.
    """

    parent_product = Product.query.get(prod_id)
    category_id = parent_product.cat_id

    brand_num = int(request.form.get("brand_id"))
    brand_num = check_brand(brand_num)

    update_parent_product(prod_id=prod_id, brand_id=brand_num)

    if category_id == 1:
        update_tent(prod_id)
        flash("Your tent listing has been updated!")
    elif category_id == 2:
        update_sleeping_bag(prod_id)
        flash("Your sleeping bag listing has been updated!")
    elif category_id == 3:
        update_sleeping_pad(prod_id)
        flash("Your sleeping pad listing has been updated!")
    else:
        return "This is unimplemented"

    return redirect("/account-info")
示例#2
0
def handle_listing(category_id):
    """Handles rental listing. """

    # Check if new brand (value -1). If so, make new brand using a helper
    # fucntion from make_update_helpers and gets the brand_id so we can pass that
    # along to make the Product object.
    brand_num = int(request.form.get("brand_id"))
    brand_num = check_brand(brand_num)

    parent_product = make_parent_product(brand_id=brand_num,
                                         category_id=category_id)

    db.session.add(parent_product)
    db.session.commit()

    if category_id == 1:
        child_product = make_tent(parent_product.prod_id)
    elif category_id == 2:
        child_product = make_sleeping_bag(parent_product.prod_id)
    elif category_id == 3:
        child_product = make_sleeping_pad(parent_product.prod_id)
    else:
        pass

    db.session.add(child_product)
    db.session.commit()

    flash("Listing successfully posted!")
    return redirect('/product-detail/%d' % parent_product.prod_id)
示例#3
0
def handle_listing(category_id):
    """Handles rental listing. """

    # Check if new brand (value -1). If so, make new brand using a helper
    # fucntion from make_update_helpers and gets the brand_id so we can pass that
    # along to make the Product object.
    brand_num = int(request.form.get("brand_id"))
    brand_num = check_brand(brand_num)

    parent_product = make_parent_product(brand_id=brand_num, category_id=category_id)

    db.session.add(parent_product)
    db.session.commit()

    if category_id == 1:
        child_product = make_tent(parent_product.prod_id)
    elif category_id == 2:
        child_product = make_sleeping_bag(parent_product.prod_id)
    elif category_id == 3:
        child_product = make_sleeping_pad(parent_product.prod_id)
    else:
        pass

    db.session.add(child_product)
    db.session.commit()

    flash("Listing successfully posted!")
    return redirect('/product-detail/%d' % parent_product.prod_id)
示例#4
0
def handle_edit_listing(prod_id):
    """ Updates both the parent and subset objects based on the edit form
        submitted in the route above.
    """

    parent_product = Product.query.get(prod_id)
    category_id = parent_product.cat_id

    brand_num = int(request.form.get("brand_id"))
    brand_num = check_brand(brand_num)

    update_parent_product(prod_id=prod_id, brand_id=brand_num)

    if category_id == 1:
        update_tent(prod_id)
        flash("Your tent listing has been updated!")
    elif category_id == 2:
        update_sleeping_bag(prod_id)
        flash("Your sleeping bag listing has been updated!")
    elif category_id == 3:
        update_sleeping_pad(prod_id)
        flash("Your sleeping pad listing has been updated!")
    else:
        return "This is unimplemented"

    return redirect("/account-info")
示例#5
0
 def test_check_brand(self):
     self.assertEqual(check_brand(3), 3)