예제 #1
0
def update_user():
    if request.method == 'POST':
        password = request.form['password']
        password_hash = ""
        if password == "":
            password_hash = ""
        else:
            password_hash = generate_password_hash(request.form['password'])

        DbUtils.update_user(request.form['id'], request.form['login'],
                            password_hash, request.form['email'],
                            request.form['user_type'],
                            request.form['full_name'])
        users = DbUtils.select_users()
        return render_template('manage_users.html',
                               users=users,
                               len=len(users),
                               login=app.config['USER'].login,
                               type=app.config['USER'].type)
    users = DbUtils.select_users()
    return render_template('manage_users.html',
                           users=users,
                           len=len(users),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #2
0
def edit_factory():
    if request.method == 'POST':
        action = request.form['submit']
        if action == "Изменить":
            manufacturers = DbUtils.select_manufacturers_name()
            formated_man = []
            for i in manufacturers:
                formated_man.append(i[0])
            return render_template('edit_factory.html',
                                   manufacturers=formated_man,
                                   id=request.form['id'],
                                   location=request.form['location'],
                                   fact_name=request.form['fact_name'],
                                   manuf_name=request.form['manuf_name'],
                                   login=app.config['USER'].login,
                                   type=app.config['USER'].type)
        elif action == "Удалить":
            DbUtils.delete_factory(request.form['id'])
            factories = DbUtils.select_factories()
            return render_template('manage_factories.html',
                                   factories=factories,
                                   len=len(factories),
                                   login=app.config['USER'].login,
                                   type=app.config['USER'].type)
    return render_template('edit_factory.html',
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #3
0
def sign_in():
    if request.method == 'POST':
        action = request.form['submit']
        if action == "Регистрация":
            return render_template('registration.html')
        login = request.form['login']
        password = request.form['password']
        p_hash = DbUtils.get_user_password(login)
        if p_hash is not None:
            if check_password_hash(DbUtils.get_user_password(login), password):
                tmp = DbUtils.select_user_full(login)
                app.config['USER'] = User(tmp[0][0], tmp[0][1], tmp[0][2],
                                          tmp[0][3], tmp[0][4])
                products = Utils.get_prod_units()
                return render_template('buy_prod_units.html',
                                       products=products,
                                       len_p=len(products),
                                       login=app.config['USER'].login,
                                       type=app.config['USER'].type)
            else:
                return render_template('index.html',
                                       messege="Неправильный логин или пароль")
        else:
            return render_template('index.html',
                                   messege="Неправильный логин или пароль")
    else:
        return redirect(url_for('index.html'))
    return render_template('index.html')
예제 #4
0
def edit_user():
    if request.method == 'POST':
        action_type = request.form['submit']
        if action_type == "Удалить":
            DbUtils.delete_user(request.form['id'])

            users = DbUtils.select_users()
            return render_template("manage_users.html",
                                   users=users,
                                   len=len(users),
                                   login=app.config['USER'].login,
                                   type=app.config['USER'].type)
        elif action_type == "Изменить":
            return render_template('edit_user.html',
                                   id=request.form['id'],
                                   login2=request.form['login'],
                                   email=request.form['email'],
                                   full_name=request.form['full_name'],
                                   user_type=request.form['user_type'],
                                   login=app.config['USER'].login,
                                   type=app.config['USER'].type)

    return render_template('edit_user.html',
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #5
0
def manage_products():
    if request.method == 'POST':
        action = request.form['submit']
        if action == "Редактировать":
            prod = Utils.get_product_id(request.form['id'])
            factories = Utils.clear_select(prod.factory,
                                           DbUtils.select_factories_names())
            types = Utils.clear_select(prod.product_type,
                                       DbUtils.select_product_types_names())
            ingredients = Utils.clear_select(prod.ingridients,
                                             DbUtils.select_ingredients_name())
            return render_template('edit_product.html',
                                   product=prod,
                                   factories=factories,
                                   types=types,
                                   ingredients=ingredients,
                                   login=app.config['USER'].login,
                                   type=app.config['USER'].type)

        elif action == "Удалить":
            DbUtils.delete_product(request.form['id'])

    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)
예제 #6
0
def add_prod_unit():
    if request.method == 'POST':
        action = request.form['s_btn']
        if action == "Поиск":
            names = DbUtils.select_products_names_find(request.form['find'])
            return render_template('add_prod_unit.html',
                                   names=names,
                                   len_n=len(names),
                                   login=app.config['USER'].login,
                                   type=app.config['USER'].type)
        elif action == "Добавить продукт":
            prod_id = DbUtils.select_products_id(
                request.form['prod_name'])[0][0]
            DbUtils.insert_product_units(prod_id, request.form['prod_count'],
                                         request.form['prod_date'], "for sale",
                                         request.form['price'])
            products = Utils.get_prod_units()
            return render_template('manage_prod_units.html',
                                   products=products,
                                   len_p=len(products),
                                   login=app.config['USER'].login,
                                   type=app.config['USER'].type)

    names = DbUtils.select_products_names()
    return render_template('add_prod_unit.html',
                           names=names,
                           len_n=len(names),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #7
0
def update_factory():
    if request.method == 'POST':
        DbUtils.update_factory(request.form['id'], request.form['location'],
                               request.form['fact_name'],
                               request.form['manuf_name'])
    factories = DbUtils.select_factories()
    return render_template('manage_factories.html',
                           factories=factories,
                           len=len(factories),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #8
0
def manage_prod_units():
    if request.method == 'POST':
        action = request.form['submit']
        if action == "Удалить":
            DbUtils.delete_product_units(request.form['id'])
    products = Utils.get_prod_units()
    return render_template('manage_prod_units.html',
                           products=products,
                           len_p=len(products),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #9
0
def add_user():
    if request.method == 'POST':
        DbUtils.insert_user(request.form['login'], request.form['password'],
                            request.form['email'], request.form['user_type'],
                            request.form['full_name'])
        users = DbUtils.select_users()
        return render_template('manage_users.html',
                               users=users,
                               len=len(users),
                               login=app.config['USER'].login,
                               type=app.config['USER'].type)
    return render_template('add_user.html',
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #10
0
 def __init__(self, obj):
     self.id = obj[0]
     self.name = obj[1]
     self.factory = DbUtils.select_factories_name(obj[2])[0][0]
     self.product_type = DbUtils.select_product_types_name(obj[3])[0][0]
     self.calories = obj[4]
     self.expiration = obj[5]
     self.dimension = obj[6]
     self.weight = obj[7]
     self.picture = obj[8]
     self.ingridients = []
     tmp = DbUtils.select_product_ingredient(obj[0])
     for i in range(len(tmp)):
         self.ingridients.append(tmp[i][0])
예제 #11
0
def registration():
    if request.method == 'POST':
        DbUtils.insert_user(request.form['login'], request.form['password'],
                            request.form['email'], request.form['user_type'],
                            request.form['full_name'])
        tmp = DbUtils.select_user_full(request.form['login'])
        app.config['USER'] = User(tmp[0][0], tmp[0][1], tmp[0][2], tmp[0][3],
                                  tmp[0][4])
        products = Utils.get_prod_units()
        return render_template('buy_prod_units.html',
                               products=products,
                               len_p=len(products),
                               login=app.config['USER'].login)

    return render_template('registration.html')
예제 #12
0
def manage_factories():
    factories = DbUtils.select_factories()
    return render_template('manage_factories.html',
                           factories=factories,
                           len=len(factories),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #13
0
def manage_users():
    users = DbUtils.select_users()
    return render_template('manage_users.html',
                           users=users,
                           len=len(users),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #14
0
def add_product():
    if request.method == 'POST':
        if 'picture' not in request.files:
            print("error !!!!")
        file = request.files['picture']

        if file.filename == '':
            return render_template('add_product.html')
        file.save(app.config['UPLOAD_FOLDER'] + file.filename)

        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'])

        prod_id = DbUtils.insert_product( 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.insert_product_ingredients(
            prod_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)
예제 #15
0
def add_factory():
    if request.method == 'POST':
        DbUtils.insert_factory(request.form['location'],
                               request.form['fact_name'],
                               request.form['manuf_name'])
        factories = DbUtils.select_factories()
        return render_template('manage_factories.html',
                               factories=factories,
                               len=len(factories),
                               login=app.config['USER'].login,
                               type=app.config['USER'].type)
    else:
        manufacturers = DbUtils.select_manufacturers_name()
        formated_man = []
        for i in manufacturers:
            formated_man.append(i[0])
        return render_template('add_factory.html',
                               manufacturers=formated_man,
                               login=app.config['USER'].login,
                               type=app.config['USER'].type)
예제 #16
0
def good_to_order():
    if request.method == 'POST':
        if app.config['ORDER_ID'] == -1:
            app.config['ORDER_ID'] = DbUtils.insert_order(
                "open", app.config['USER'].id)
        DbUtils.insert_good(request.form['id'], request.form['count'],
                            app.config['ORDER_ID'])
        products = Utils.get_prod_units()
        return render_template('buy_prod_units.html',
                               products=products,
                               len_p=len(products),
                               login=app.config['USER'].login,
                               type=app.config['USER'].type,
                               messege="Товар успешно добавлен в корзину")
    products = Utils.get_prod_units()
    return render_template('buy_prod_units.html',
                           products=products,
                           len_p=len(products),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #17
0
def basket():
    if request.method == 'POST':
        return render_template('basket.html',
                               products=None,
                               len_p=0,
                               login=app.config['USER'].login,
                               summ=0,
                               messege="Ваш заказ успешно подтверждён.")
    products = DbUtils.select_goods(app.config['ORDER_ID'])
    summ = 0
    for i in range(len(products)):
        summ += products[i][5] * products[i][1]
    return render_template('basket.html',
                           products=products,
                           len_p=len(products),
                           login=app.config['USER'].login,
                           summ=summ)
예제 #18
0
def manage_product_type():
    if request.method == 'POST':
        action = request.form['submit']
        if action == "Добавить":
            DbUtils.insert_product_types(request.form['prod_type_name'])
        elif action == "Сохранить изменения":
            DbUtils.update_product_types(request.form['id'],
                                         request.form['prod_type_name'])
        elif action == "Удалить":
            DbUtils.delete_product_types(request.form['id'])

    pr_types = DbUtils.select_product_types()
    return render_template('manage_product_type.html',
                           product_types=pr_types,
                           len=len(pr_types),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #19
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)
예제 #20
0
def manage_manufacturers():
    if request.method == 'POST':
        action = request.form['submit']
        if action == "Добавить":
            DbUtils.insert_manufacturer(request.form['email'],
                                        request.form['comp_name'])
        elif action == "Сохранить изменения":
            DbUtils.update_manufacturer(request.form['id'],
                                        request.form['email'],
                                        request.form['comp_name'])
        elif action == "Удалить":
            DbUtils.delete_manufacturer(request.form['id'])

    manufacturers = DbUtils.select_manufacturers()
    return render_template('manage_manufacturers.html',
                           manufacturers=manufacturers,
                           len=len(manufacturers),
                           login=app.config['USER'].login,
                           type=app.config['USER'].type)
예제 #21
0
 def get_product_id(id):
     tmp = DbUtils.select_product_id(id)
     return Product(tmp[0])
예제 #22
0
 def get_products():
     tmp = DbUtils.select_products()
     result = []
     for i in range(len(tmp)):
         result.append(Product(tmp[i]))
     return result