コード例 #1
0
def product_create():
    """Provide HTML form to create a new product."""
    form = ProductForm(request.form)
    if request.method == 'POST' and form.validate():
        mongo.db.products.insert_one(form.data)
        # Success. Send user back to full product list.
        return redirect(url_for('products_list'))
    # Either first load or validation error at this point.
    return render_template('product/edit.html', form=form)
コード例 #2
0
ファイル: app.py プロジェクト: chiaraF16/FlaskExerciseCF
def product():
    form = ProductForm(request.form)
    if form.validate():
        name = form.name.data
        description = form.description.data
        price = form.price.data
        mongo.db.products.insert_one({'name': name, 'description': description, 'price': price})
        return redirect('/')
    return render_template('product/create.html', form=form)
コード例 #3
0
ファイル: app.py プロジェクト: pabloac31/flask-app
def product_edit(product_id):
  product = mongo.db.products.find_one({ "_id": ObjectId(product_id) })
  form = ProductForm(request.form)
  if request.method == 'POST' and form.validate():
    mongo.db.products.replace_one(product,form.data)
    # Success. Send user back to full product list.
    return redirect(url_for('products_list'))
    # Either first load or validation error at this point.
  return render_template('product/edit.html', form=form)
コード例 #4
0
ファイル: app.py プロジェクト: chiaraF16/FlaskExerciseCF
def product_edit(product_id):
    prod = mongo.db.products.find_one({"_id": ObjectId(product_id)})
    form = ProductForm(request.form)
    if form.validate():
        name = form.name.data
        description = form.description.data
        price = form.price.data
        mongo.db.products.replace_one(prod, {'name': name, 'description': description, 'price': price})
        return redirect('/')

    return render_template('product/edit.html', product=prod, form=form)
コード例 #5
0
def product_edit(product_id):
    """Provide HTML form to create a new product."""
    form = ProductForm(request.form)
    if request.method == 'POST' and form.validate():
        # product = mongo.db.products.find_one({ "_id": ObjectId(product_id) })
        mongo.db.products.update_one({'_id': ObjectId(product_id)},
                                     {"$set": form.data})
        # Success. Send user back to full product list.
        return redirect(url_for('products_list'))
    # Either first load or validation error at this point.
    return render_template('product/edit.html', form=form)
コード例 #6
0
ファイル: app.py プロジェクト: AGregorc/Flask-fooapp
def product_edit(product_id):
    form = ProductForm(request.form)
    if request.method == 'POST' and form.validate():
        mongo.db.products.replace_one({'_id': ObjectId(product_id)}, form.data)
        # Success. Send user back to full product list.
        return redirect(url_for('products_list'))
    # Query: get Product object by ID.
    product = mongo.db.products.find_one({"_id": ObjectId(product_id)})
    if product is None:
        # Abort with Not Found.
        abort(404)
    form.name.data = product['name']
    form.description.data = product['description']
    form.price.data = product['price']
    return render_template('product/edit.html', form=form, title="Edit product")
コード例 #7
0
def product_edit(product_id):
    form = ProductForm(request.form)
    product = mongo.db.products.find_one({"_id": ObjectId(product_id)})

    if product is None:
        # Abort with Not Found.
        abort(404)

    if request.method == 'POST' and form.validate():
        mongo.db.products.update_one({"_id": ObjectId(product_id)},
                                     {"$set": form.data})
        # Success. Send user back to full product list.
        return redirect(url_for('products_list'))
    form = ProductForm(request.form,
                       name=product['name'],
                       description=product['description'],
                       price=product['price'])
    # Either first load or validation error at this point.
    return render_template('product/edit.html', form=form)
コード例 #8
0
def product_edit(product_id):
    product = mongo.db.products.find_one({"_id": ObjectId(product_id)})
    if product is None:
        abort(404)
    #Filling form with "original" data
    form = ProductForm(request.form, data=product)
    if request.method == 'POST' and form.validate():
        mongo.db.products.update_one({"_id": ObjectId(product_id)}, {
            '$set': {
                'name': form.name.data,
                'description': form.description.data,
                'price': form.price.data
            },
        },
                                     upsert=False)

        #Update product for the render_template
        product = mongo.db.products.find_one({"_id": ObjectId(product_id)})
        # Success. Send the user back to the detail view.
        return render_template('product/detail.html', product=product)
    return render_template('product/edit.html', form=form)