Exemple #1
0
def updateItem(user, isbn, qty):  #update quantity of items
    #accessed from viewcart page
    if int(qty) != 0:
        query = 'update cart set qty =' + qty + ' where cust_id =\'' + user + '\' and isbn=\'' + isbn + '\''
    else:  #if customer set quantity to zero, just remove from cart
        query = 'delete from cart where cust_id =\'' + user + '\' and isbn=\'' + isbn + '\''
    db.update(query)
Exemple #2
0
def checkout(data):
    order_num = str(data['order_num'])
    total = str(data['total'])
    query = 'insert into orders(customer_id,order_num,order_id,order_date,ship_add,total,items) values (\'' + data[
        'customer_id'] + '\',\'' + order_num + '\',\'' + data[
            'order_id'] + '\',\'' + data['order_date'] + '\',\'' + data[
                'ship_add'] + '\',\'' + total + '\',\'' + data['items'] + '\')'
    db.update(query)
Exemple #3
0
def update_info(data):
    username = data['user']
    username2 = data['user2']
    email = data['email']
    name = data['name']
    query = "UPDATE accounts SET email='{}', name='{}', username='******' WHERE username='******'".format(
        email, name, username2, username)
    db.update(query)
Exemple #4
0
def add_user(data):
    name = data['name']
    email = data['email']
    birth = data['birth']
    username = data['username']
    password = data['password']
    acct_type = data['acct_type']
    query = "INSERT INTO accounts(name,email,birthdate,username,password,acct_type) VALUES('" + name + "','" + email + "','" + birth + "','" + username + "','" + password + "','" + acct_type + "')"
    db.update(query)
Exemple #5
0
def update_user(data):  #contains dict of all user attributes?
    name = data['name']
    email = data['email']
    birth = data['birth']
    username = data['username']
    password = data['password']
    acct_type = data['acct_type']
    query = "UPDATE accounts SET name = '" + name + "',email = '" + email + "', birthdate = '" + birth + "',username = '******',password = '******', acct_type = '" + acct_type + "' WHERE username='******'"
    db.update(query)
Exemple #6
0
def getItems(user):
    query = 'select isbn,qty from cart where cust_id=\'' + user + '\''
    isbns = db.select(query)[0]
    info = []
    j = 0
    for i in isbns:
        query = 'select title,author,price,pic_url,isbn from books where isbn=\'' + i[
            'isbn'] + '\''
        dict = db.select(query)[0][0]
        dict['qty'] = i['qty']
        dict['total'] = float(dict['qty']) * float(dict['price'])
        info.append(dict)  #get the price totals for each book in cart
        j = j + 1
    #assigns list of dicts with information of books in the cart
    return info  #return the list
Exemple #7
0
def register(acc):
    query = "select * from accounts where username='******' and password='******'".format(
        acc.name, acc.passw)
    num = db.select(query)[1]  #returns number of tuples found by query
    if (num == 0):
        query = "insert into accounts(name,email,birthdate,username,password,acct_type) values ('{}','{}','{}','{}','{}','{}')".format(
            acc.name, acc.email, acc.date, acc.user, acc.passw, acc.type)
        db.update(query)
        query = "insert into address(add_line_1,add_line_2,state,zip,cust_id,city) values ('{}','{}','{}','{}','{}','{}')".format(
            acc.addr.ad1, acc.addr.ad2, acc.addr.st, acc.addr.zip, acc.user,
            acc.addr.city)
        db.update(query)
    else:
        num = 1
    return num
def salesReport():
    query = 'select * from orders'
    orders = db.select(query)[0]
    totalmoneys = 0
    for i in orders:
        totalmoneys += i['total']
    return orders,totalmoneys
def dayReport():
    today = str(date.today())
    query = 'select * from orders where order_date ='  + today
    orders = db.select(query)[0]
    totalmoneys = 0
    for i in orders:
        totalmoneys += i['total']
    return orders, totalmoneys
def login(creds):
    query = 'select * from accounts where username=\'' + creds[
        'user'] + '\' and password=\'' + creds['pass'] + '\''
    num = db.select(query)[1]  #returns number of tuples found by query
    if num == 0:
        return False
    else:
        return True
Exemple #11
0
def login(creds):
    query = "select * from accounts where username='******' and password='******'".format(
        creds['user'], creds['pass'])
    num = db.select(query)[1]  #returns number of tuples found by query
    if num == 0:
        return False
    else:
        return True
Exemple #12
0
def getNumItems(
    user
):  #used to set number in cookie to show beside the cart link in nav bar
    query = 'select count(cust_id) from cart where cust_id=\'' + user + '\' group by cust_id'
    inf = db.select(query)
    if inf[1] != 0:  #check if any tuples were returned
        return inf[0][0]['count(cust_id)']
    else:
        return 0  #if no items in cart
Exemple #13
0
def getNumItems(
    user
):  #used to set number in cookie to show beside the cart link in nav bar
    query = "select count(cust_id) from cart where cust_id='{}' group by cust_id".format(
        user)
    inf = db.select(query)
    number = 'count(cust_id)'.encode('ASCII')
    if inf[1] != 0:  #check if any tuples were returned
        return inf[0][0].get(number)

    else:
        return 0  #if no items in cart
def rmv_user(user):
    query = 'delete from accounts where username = \'' + user + '\''
    db.update(query)
def give_perm(user, level):
    query = 'update accounts set acct_type = \'' + level + '\' where username = \'' + user + '\''
    db.update(query)
def register(acc):
    query = 'insert into accounts(name,email,birthdate,username,password,acct_type) values (\'' + acc.name + '\',\'' + acc.email + '\',' + acc.date + ',\'' + acc.user + '\',\'' + acc.passw + '\',\'' + acc.type + '\')'
    db.update(query)
    query = 'insert into address(add_line_1,add_line_2,state,zip,cust_id,city) values (\'' + acc.addr.ad1 + '\',\'' + acc.addr.ad2 + '\',\'' + acc.addr.st + '\',\'' + acc.addr.zip + '\',\'' + acc.user + '\',\'' + acc.addr.city + '\')'
    db.update(query)
    return query
def verify_type(creds):
    return db.select('SELECT acct_type FROM accounts WHERE username=\'' +
                     creds['user'] + '\'')[0][0]['acct_type']
Exemple #18
0
def addItem(user, isbn):  #or just send both in dict or list
    #if first time putting item in cart
    query = 'insert into cart(cust_id,isbn,qty) values (\'' + user + '\',\'' + isbn + '\',1)'
    db.update(query)
Exemple #19
0
def get_info(data):
    query = "select * from accounts where username='******'".format(data)
    return db.select(query)[0]
Exemple #20
0
def update_pass(data):
    username = data['user']
    password = data['newpasswd']
    query = "UPDATE accounts SET password = '******' WHERE username='******'"
    db.update(query)
def checkInventory(isbn):
    #whenever items are checked out and stock of items changes, check to see if
    #below certain threshold...guess like 5
    query = 'select amount from books where isbn = \'' + isbn +'\''
    if db.select(query)[0][0]['amount'] < 5:
Exemple #22
0
def rmv_user(data):
    user = data['username']
    query = 'delete from accounts where username = \'' + user + '\''
    db.update(query)
Exemple #23
0
def getAll():
    query = 'select * from books'
    return db.select(query)[0]
Exemple #24
0
def verify_type(creds):
    return db.select(
        "SELECT acct_type FROM accounts WHERE username='******'".format(creds))[0]
Exemple #25
0
def getSearch(data):
    query = 'select * from books where ' + data['cat'] + ' = \'' + data[
        'search'] + '\''
    return db.select(query)[0]
Exemple #26
0
def getBook(isbn):
    query = 'select * from books where isbn = \'' + isbn + '\''
    return db.select(query)[0]