Example #1
0
def delete_news(drug_id):
    if 'username' not in session:
        return redirect('/login')
    if session['username'] != 'admin':
        return redirect('/login')
    dm = DrugModel(db.get_connection())
    dm.delete(drug_id)
    return redirect("/index")
Example #2
0
def delete_basket(drug_id):
    if 'username' not in session:
        return redirect('/login')
    bask = BasketModel(db.get_connection())
    bask.delete(drug_id, session['user_id'])
    drug = DrugModel(db.get_connection())
    drug.update(drug_id, -1)
    return redirect('/basket')
Example #3
0
def addbasket(drug_id):
    if 'username' not in session:
        return redirect('/login')
    bm = BasketModel(db.get_connection())
    bm.insert(drug_id, session['user_id'])
    drug = DrugModel(db.get_connection())
    drug.update(drug_id)
    return redirect("/index")
Example #4
0
def basket():
    if 'username' not in session:
        return redirect('/login')
    basket = BasketModel(db.get_connection()).get_all(session['user_id'])
    drug = DrugModel(db.get_connection())
    bask = []
    for i in basket:
        bask.append(drug.get(i[1]))
    return render_template('basket.html',
                           username=session['username'],
                           news=bask)
Example #5
0
def add_news():
    if 'username' not in session:
        return redirect('/login')
    if session['username'] != 'admin':
        return redirect('/login')
    form = AddDrugForm()
    if form.validate_on_submit():
        name = form.name.data
        discription = form.discript.data
        number = form.number.data
        dm = DrugModel(db.get_connection())
        dm.insert(name, discription, number, session['user_id'])
        return redirect("/index")
    return render_template('add_drug.html',
                           title='Добавление товара',
                           form=form,
                           username=session['username'])
Example #6
0
def index():
    if 'username' in session:
        name = session['username']
    else:
        name = 'Вход'
    dm = DrugModel(db.get_connection()).get_all()
    drug = []
    for i in dm:
        if int(i[3]) > 0:
            drug.append(i)
    return render_template('index.html', username=name, news=drug)
Example #7
0
from db import DB
from user import UserModel
from drug import DrugModel
from basket import BasketModel


db = DB()
users_model = UserModel(db.get_connection())
users_model.init_table()
users_model.insert("admin", "admin")
news_model = DrugModel(db.get_connection())
news_model.init_table()
basket_model = BasketModel(db.get_connection())
basket_model.init_table()