Example #1
0
def products_create():
    form = ProductForm(request.form)

    if not form.validate():
        return render_template("products/new.html",
                               form=form,
                               categories=Category.query.all())

    # selection from form & dropdown list
    category_name = request.form.get("select")

    # get category
    category = Category.query.filter_by(name=category_name).first()

    product = Product(form.name.data, form.price.data, form.description.data)
    product.account_id = current_user.id
    product.category_id = category.id

    db.session().add(product)

    try:
        db.session().commit()
    except:
        db.session.rollback()

    return redirect(url_for("auth_user"))
Example #2
0
def products_create():
    form = ProductForm(request.form)

    if not form.validate():
        return render_template("products/new.html", form=form)

    t = Product(form.name.data, form.producer.data)
    t.public = form.public.data
    t.account_id = current_user.id

    db.session().add(t)
    db.session().commit()

    return redirect(url_for("products_index"))
Example #3
0
def products_create():
    form = ProductForm(request.form)

    if not form.validate():
        return render_template("products/new.html", form = form)
    
    p = Product(form.name.data, form.description.data)
    p.account_id = current_user.id
    p.onSale = True

    db.session().add(p)
    db.session().commit()

    return redirect(url_for("products_index"))
Example #4
0
def products_create():
    form = ProductForm(request.form)

    if not form.validate():
        return render_template("products/new.html", form=form)

    product = Product(request.form.get("name"), request.form.get("amount"),
                      request.form.get("price"))

    product.account_id = current_user.id

    db.session().add(product)
    db.session().commit()

    return redirect(url_for("products_list"))