Exemple #1
0
def items_create():
    form = ItemForm(request.form)
    form2 = CategoryForm(request.form)

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

    name = form.name.data
    it = Item.query.filter_by(name=name).first()
    if it:
        return render_template("items/new.html",
                               form=form,
                               error="Item is already listed!")
    i = Item(name)

    cid = form.category_id.data
    c = Category.query.get(cid)
    if not c:
        return render_template("categories_index")
    c.size = c.size + 1
    i.category_id = cid

    i.bought = form.bought.data
    i.account_id = current_user.id

    db.session().add(i)
    db.session().commit()

    return redirect(url_for("items_index"))
Exemple #2
0
def items_create():
    form = ItemForm(request.form)
    list = Category.query.all()

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

    i = Item(form.name.data, form.amount.data)
    i.bought = form.bought.data
    i.account_id = current_user.id
    i.category_id = form.category.data
    i.list_id = List.find_users_defaultlist_id(current_user.id)

    db.session().add(i)
    db.session().commit()

    return redirect(url_for("items_index"))