Пример #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"))
Пример #2
0
def items_create():
    form = ItemForm(request.form)

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

    i = Item(form.name.data)
    i.vegan = form.vegan.data
    i.account_id = current_user.id

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

    return redirect(url_for("items_index"))
Пример #3
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"))
Пример #4
0
def items_create():
    form = ItemForm(request.form)

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

    new_item = Item(form.name.data, 
                    form.description.data,
                    form.price.data)
    
    new_item.account_id = current_user.id
    gameName = form.gameName.data

    db.session().add(new_item)
    add_gameName_to_item(new_item, gameName)

    db.session().commit()
  
    return redirect(url_for('item_add_games', item_id = new_item.id))
Пример #5
0
def items_create():

    form = ItemForm(request.form)
    form.item_category.choices = [
        (c.id, c.name) for c in Category.query.order_by('name').filter_by(
            account_id=current_user.id)
    ]

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

    i = Item(form.name.data, form.expired.data)
    category = Category.query.get(form.item_category.data)
    i.account_id = current_user.id
    i.category_id = category.id

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

    return redirect(url_for("items_index"))
Пример #6
0
def item_form():

    form = ItemForm(request.form)

    if request.method == "GET":
        return render_template("items/new.html", form=form)

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

    cc = Colorcode.query.filter(
        Colorcode.code == form.colorcode.data.code).first()
    ptype = Ptype.query.filter(Ptype.name == form.ptype.data.name).first()

    validProduct = Cc_ptype.query.filter(
        Cc_ptype.colorcode_id == cc.id, Cc_ptype.ptype_id == ptype.id).first()
    if not validProduct:
        return render_template("items/new.html",
                               form=form,
                               error="Product does not exist.")

    duplicate = Item.query.filter(Item.colorcode_id == cc.id,
                                  Item.ptype_id == ptype.id,
                                  Item.account_id == current_user.id).first()

    if duplicate:
        return render_template("items/new.html",
                               form=form,
                               error="Product already in collection.")

    item = Item()
    item.colorcode_id = cc.id
    item.ptype_id = ptype.id
    item.account_id = current_user.id

    db.session.add(item)
    db.session().commit()

    return redirect(url_for("index"))