def add_category(): if request.method == 'POST': new_category = request.form['new_category'] with ContextManagerSQLite('product.db') as s: sql = f'INSERT INTO categories (category) VALUES (?)' s.execute(sql, [new_category]) title = 'VentPortal' return render_template('add_category.html', title=title)
def categories_admin(): category = [] with ContextManagerSQLite('product.db') as s: query_response = s.execute('SELECT category FROM categories ') for c in query_response: category += c title = 'VentPortal' return render_template('admin.html', title=title, category=category)
def add_product(): category = {} with ContextManagerSQLite('product.db') as s: query_response = s.execute('SELECT id, category FROM categories ') for c in query_response: (c_id, c_category) = c category.update({c_id: c_category}) if request.method == 'POST': new_product = request.form['new_product'] price = request.form['price'] description = request.form['description'] quantity = request.form['quantity'] id_category = request.form['id_category'] with ContextManagerSQLite('product.db') as s: sql = f'INSERT INTO products (product, price, description, quantity, id_category) VALUES (?, ?, ?, ?, ?)' s.execute(sql, [new_product, price, description, quantity, id_category]) title = 'VentPortal' return render_template('add_product.html', title=title, category=category)
def check_wishes(value): w_wishes_user = '' user_id = str(value) sql = 'SELECT id, wishes FROM users WHERE id_telegram=? ' with ContextManagerSQLite('people.db') as s: query_response = s.execute(sql, [user_id]) for w in query_response: w_id, w_wishes_user = w if w_wishes_user != '0': return False else: return True
def check_email(value): e_email_user = '' user_id = str(value) sql = 'SELECT id, email FROM users WHERE id_telegram=? ' with ContextManagerSQLite('people.db') as s: query_response = s.execute(sql, [user_id]) for e in query_response: e_id, e_email_user = e if e_email_user != '0': return False else: return True
def check_tel(value): t_tel_user = '' user_id = str(value) sql = 'SELECT id, tel FROM users WHERE id_telegram=? ' with ContextManagerSQLite('people.db') as s: query_response = s.execute(sql, [user_id]) for t in query_response: t_id, t_tel_user = t if t_tel_user != '0': return False else: return True
def check_name(value): n_name_user = '' user_id = str(value) sql = 'SELECT id, name FROM users WHERE id_telegram=? ' with ContextManagerSQLite('people.db') as s: query_response = s.execute(sql, [user_id]) for n in query_response: n_id, n_name_user = n if n_name_user != '0': return False else: return True
def check_id(value): users_id = [] user_id = value sql = 'SELECT id, id_telegram FROM users ' with ContextManagerSQLite('people.db') as s: query_response = s.execute(sql) for i in query_response: i_id, i_id_telegram = i users_id.append(i_id_telegram) if str(user_id) in users_id: return False else: return True
def buy(category, products): with ContextManagerSQLite('product.db') as s: sql = f'SELECT product, price ' \ f'FROM products ' \ f'WHERE product="{products}" ' query_response = s.execute(sql) for p in query_response: p_product, p_price = p p_productl = p_product title = 'VentPortal' return render_template('buy.html', title=title, category=category, products=products, p_product=p_productl)
def products(category): products = [] with ContextManagerSQLite('product.db') as s: sql = f'SELECT product FROM products ' \ f'INNER JOIN categories ' \ f'ON products.id_category=categories.id ' \ f'WHERE category="{category}" AND quantity <> 0 ' query_response = s.execute(sql) for p in query_response: products += p title = 'VentPortal' return render_template('products.html', title=title, category=category, products=products)
def product(category, products): with ContextManagerSQLite('product.db') as s: sql = f'SELECT product, price, description, quantity ' \ f'FROM products ' \ f'INNER JOIN categories ' \ f'ON products.id_category=categories.id ' \ f'WHERE category="{category}" AND product="{products}" ' query_response = s.execute(sql) for p in query_response: p_product, p_price, p_description, p_quantity = p p_productl = p_product p_pricel = p_price p_descriptionl = p_description p_quantityl = p_quantity title = 'VentPortal' return render_template('product.html', title=title, category=category, products=products, p_product=p_productl, p_price=p_pricel, p_description=p_descriptionl, p_quantity=p_quantityl)
def add_email(value): sql = 'UPDATE users SET email=? WHERE email=? ' with ContextManagerSQLite('people.db') as s: s.execute(sql, [value, str(0)])
def add_id_telegram(value): with ContextManagerSQLite('people.db') as s: sql = f'INSERT INTO users (id_telegram) VALUES (?) ' s.execute(sql, [value])
def add_wishes(value): sql = 'UPDATE users SET wishes=? WHERE wishes=? ' with ContextManagerSQLite('people.db') as s: s.execute(sql, [value, str(0)])