Esempio n. 1
0
File: app.py Progetto: praat6/fooApp
def product_edit(product_id):
    product = mongo.db.products.find_one({"_id": ObjectId(product_id)})
    if product is None:
        # Abort with Not Found.
        abort(404)
    #Fill form with current data
    update = ProductForm(request.form)
    update.fill(product["name"], product["description"], product["price"])
    #Create an empty form for the update
    form = ProductForm(request.form)
    if request.method == 'POST' and form.validate():
        update.fill(form.name.data, form.description.data, form.price.data)
        mongo.db.products.update_one(product, {"$set": update.data})
        return redirect(url_for('products_list'))
    return render_template('product/edit.html', form=update)
Esempio n. 2
0
def product_edit(product_id):
    product = mongo.db.products.find_one({"_id": ObjectId(product_id)})
    if product is None:
        abort(404)

    form = ProductForm(request.form)

    if request.method == 'POST' and form.validate():
        mongo.db.products.update_one({"_id": ObjectId(product_id)}, {
            '$set': {
                'name': form.data['name'],
                'description': form.data['description'],
                'price': form.data['price']
            }
        })

        return redirect(url_for('products_list'))

    form.fill(product)
    return render_template('product/edit.html', form=form)