def bookview(): pres = bh.handle_book('home', '') #if the request has cookies (Logged in) will load this if request.cookies.get('username') != None: acc_type = handle_acc( 'type', request.cookies.get('username'))[0].get('acct_type') if (acc_type == 'customer'): resp = render_template('index.htm', p=pres, user=request.cookies.get('username'), count=request.cookies.get('count'), log="Logout") elif (acc_type == 'owner'): resp = redirect('/owner') elif (acc_type == 'vendor'): resp = redirect('/vendor') elif (acc_type == 'admin'): resp = redirect('/admin', 302) else: resp = 'How did you get here???' else: books = bh.handle_book('home', '') resp = make_response( render_template('index.htm', p=books, user='******', count=0, log="Login")) return resp
def checkoutview(): resp = redirect("/cart") if (request.method == 'POST'): itemString = "" item, sub = ch.handle_cart('view', request.cookies.get('username')) info = handle_acc('profile', request.cookies.get('username')) empty = item itemsList = list() for book in item: itemString += book['title'] itemsList.append(item) data = request.form.copy() data['customer_id'] = request.cookies.get('username') data['order_num'] = random.randint(100000000, 999999999) data['order_id'] = data['customer_id'] + str(data['order_num']) data['order_date'] = str(date.today()) data['ship_add'] = data.get("add1s") + " " + data.get( "add2s") + " " + data.get("citys") + ", " + data.get( "states") + " " + data.get("zips") data['bill_add'] = data.get("add1") + " " + data.get( "add2") + " " + data.get("city") + ", " + data.get( "state") + " " + data.get("zip") data['itemsList'] = itemsList data['items'] = itemString data['total'] = sub respo = make_response( render_template('confirm.htm', count=request.cookies.get('count'), items=item, subtotal=sub, details=info[0], conf_nmb=data['order_num'], date=data['order_date'], conf_id=data['order_id'], ship_add=data['ship_add'])) orderConfirmation(info[0]['email'], data) ch.handle_cart('checkout', data) for book in empty: cp.updateItem(request.cookies.get('username'), book['isbn'], 0) bh.handle_book('checkout', book['isbn']) respo.set_cookie('count', str(0)) return respo #Should take input from form and put into order object else: if int(request.cookies.get('count')) != 0: item, sub = ch.handle_cart('view', request.cookies.get('username')) return render_template('checkout.htm', count=request.cookies.get('count'), items=item, subtotal=sub) else: return redirect('/cart') resp = redirect('static/checkoutproto.htm') return resp
def ownerViewSelection(report): resp = '' if (report == 'daily'): dictlist = bh.handle_book('dailySale', str(date.today())) resp = make_response( render_template('endOfDaySales.htm', items=dictlist, date=str(date.today()))) elif (report == 'inventory'): dictlist = bh.handle_book('lowInv', '0') resp = make_response( render_template('lowInventory.htm', items=dictlist, date=str(date.today()))) return resp
def search(): if request.method == 'POST': dictlist = bh.handle_book('search',request.form.copy()) resp = '' template = Template(filename=r'D:\bookworm\templates\search.htm') resp = make_response(template.render(items=dictlist,acct_name=request.cookies.get('username'))) return resp
def bookview(): p = bh.handle_book('home','') if request.cookies.get('username') != None: template = Template(filename=r'D:\bookworm\templates\index.htm') resp = make_response(template.render(presidents=p,user=request.cookies.get('username'),count=request.cookies.get('count'))) #if the request has cookies will load this else: template = Template(filename=r'D:\bookworm\templates\indexg.htm') resp = make_response(template.render(presidents=p)) return resp
def adminviewselection(action): resp = '' if (request.method == 'POST'): data = request.form.copy() if (action == 'book'): if (data['radiobutton'] == 'add'): bh.handle_book('add', data) resp = render_template('manageBooks.htm', Confirmation="Book added!") elif (data['radiobutton'] == 'delete'): bh.handle_book('delete', data) resp = render_template('manageBooks.htm', Confirmation="Book deleted!") elif (data['radiobutton'] == 'update'): bh.handle_book('update', data) resp = render_template('manageBooks.htm', Confirmation="Book updated!") elif (action == 'account'): if (data['radiobutton'] == 'add'): handle_acc('add', data) resp = render_template('manageAccounts.htm', Confirmation="Account added!") elif (data['radiobutton'] == 'delete'): handle_acc('delete', data) resp = render_template('manageAccounts.htm', Confirmation="Account deleted!") elif (data['radiobutton'] == 'update'): handle_acc('update', data) resp = render_template('manageAccounts.htm', Confirmation="Account updated!") elif (action == 'order'): if (data['radiobutton'] == 'add'): handle_acc('add', data) resp = render_template('manageOrders.htm', Confirmation="Order added!") elif (data['radiobutton'] == 'delete'): handle_acc('delete', data) resp = render_template('manageOrders.htm', Confirmation="Order deleted!") elif (data['radiobutton'] == 'update'): handle_acc('update', data) resp = render_template('manageOrders.htm', Confirmation="Order updated!") else: if (action == 'book'): resp = redirect( 'http://jsmalls128.pythonanywhere.com/static/manageBooks.htm') elif (action == 'account'): resp = redirect( 'http://jsmalls128.pythonanywhere.com/static/manageAccounts.htm' ) elif (action == 'order'): resp = redirect( 'http://jsmalls128.pythonanywhere.com/static/manageOrders.htm') else: resp = "How did you get here?!?!?!" return resp
def search(): if request.method == 'POST': dictlist = bh.handle_book('search', request.form.copy()) if request.cookies.get('username') != None: resp = render_template('search.htm', items=dictlist, user=request.cookies.get('username'), count=request.cookies.get('count'), log="Logout") else: resp = render_template('search.htm', items=dictlist, user="******", count=0, log="Login") return resp
def selBook(): if request.method == 'POST': data = request.form.copy() data['user'] = request.cookies.get('username') ch.handle_cart('add',data) resp = redirect("/cart") resp.set_cookie('count',str(int(request.cookies.get('count'))+1)) else: isbn = request.args.get('book') info = bh.handle_book('view',isbn) if request.cookies.get('username') != None: template = Template(filename=r'D:\bookworm\templates\book.htm') resp = make_response(template.render(details=info[0],count=request.cookies.get('count'))) #if the request has cookies will load this else: template = Template(filename=r'D:\bookworm\templates\bookg.htm') resp = make_response(template.render(details=info[0])) return resp
def selBook(): if request.method == 'POST': data = request.form.copy() data['user'] = request.cookies.get('username') ch.handle_cart('add', data) resp = redirect("/cart") resp.set_cookie('count', str(int(request.cookies.get('count')) + 1)) else: isbn = request.args.get('book') info = bh.handle_book('view', isbn) if request.cookies.get('username') != None: resp = render_template('book.htm', details=info[0], user=request.cookies.get('username'), count=request.cookies.get('count'), log="Logout") #if the request has cookies will load this else: resp = render_template('book.htm', details=info[0], user='******', count=0, log="Login") return resp
def vendorviewselection(): resp = '' if (request.method == 'POST'): data = request.form.copy() if (data['radiobutton'] == 'add'): bh.handle_book('add', data) resp = render_template('manageBooks.htm', Confirmation="Book added!") elif (data['radiobutton'] == 'delete'): bh.handle_book('delete', data) resp = render_template('manageBooks.htm', Confirmation="Book deleted!") elif (data['radiobutton'] == 'update'): bh.handle_book('update', data) resp = render_template('manageBooks.htm', Confirmation="Book updated!") else: resp = redirect('/static/vendor.htm') return resp
def adminview(): resp = '' if (request.method == 'POST'): data = request.form.copy() if (data['radiobutton'] == 'add'): bh.handle_book('add', data) resp = render_template('manageBooks.htm', Confirmation="Book added!") elif (data['radiobutton'] == 'delete'): bh.handle_book('delete', data) resp = render_template('manageBooks.htm', Confirmation="Book deleted!") elif (data['radiobutton'] == 'update'): bh.handle_book('update', data) resp = render_template('manageBooks.htm', Confirmation="Book updated!") else: resp = render_template('adminMain.htm', user=request.cookies.get('username'), log="Logout") return resp