Ejemplo n.º 1
0
def edit_product():
    if request.method == 'POST':
        expiration_size = request.form['expitation_size']

        if expiration_size == "час":
            expiration = int(request.form['expitation_value'])

        elif expiration_size == "день":
            expiration = 24 * int(request.form['expitation_value'])

        elif expiration_size == "месяц":
            expiration = 730 * int(request.form['expitation_value'])

        elif expiration_size == "год":
            expiration = 8760 * int(request.form['expitation_value'])
        file = request.files['picture']
        if file.filename == "":
            DbUtils.update_product(request.form['id'], request.form['prod_name'],\
                                         DbUtils.select_factories_id(request.form['factory'])[0][0], \
                                         DbUtils.select_product_types_id(request.form['type'])[0][0], \
                                         request.form['calorie_content'],\
                                         expiration,\
                                         request.form['dimension'],\
                                         request.form['weight'])
        else:
            file.save(app.config['UPLOAD_FOLDER'] + file.filename)
            DbUtils.update_product_pic(
                request.form['id'], request.form['prod_name'],
                DbUtils.select_factories_id(request.form['factory'])[0][0],
                DbUtils.select_product_types_id(request.form['type'])[0][0],
                request.form['calorie_content'], expiration,
                request.form['dimension'], request.form['weight'],
                file.filename)

        DbUtils.delete_product_ingredient(request.form['id'])
        DbUtils.insert_product_ingredients(
            request.form['id'], request.form.getlist('ingredient[]'))

        products = Utils.get_products()
        return render_template('manage_products.html',
                               products=products,
                               len_p=len(products),
                               login=app.config['USER'].login,
                               type=app.config['USER'].type)

    factories = DbUtils.select_factories_names()
    types = DbUtils.select_product_types_names()
    ingredients = DbUtils.select_ingredients()
    return render_template('add_product.html',
                           factories=factories,
                           len_f=len(factories),
                           types=types,
                           len_t=len(types),
                           ingredients=ingredients,
                           len_i=len(ingredients),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
Ejemplo n.º 2
0
def manage_ingredients():
    if request.method == 'POST':
        action = request.form['submit']
        if action == "Добавить":
            DbUtils.insert_ingredients(request.form['ing_name'],
                                       request.form['dimension'])
        elif action == "Сохранить изменения":
            DbUtils.update_ingredients(request.form['id'],
                                       request.form['ing_name'],
                                       request.form['dimension'])
        elif action == "Удалить":
            DbUtils.delete_ingredients(request.form['id'])

    ingredients = DbUtils.select_ingredients()
    return render_template('manage_ingredients.html',
                           ingredients=ingredients,
                           len=len(ingredients),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)