Commit c6324500 authored by Joel's avatar Joel
Browse files

Pre final changes

parent 4807a325
......@@ -34,12 +34,12 @@ class CustOrders(db.Model):
# __tablename__ = 'users'
serial = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(100), db.ForeignKey('login.email'))
order_id = db.Column(db.String(100))
order_id = db.Column(db.Integer)
datetime = db.Column(db.DateTime)
isbn=db.Column(db.String(20))
isbn=db.Column(db.String)
quantity=db.Column(db.Integer)
price=db.Column(db.Integer)
def __init__(self, serial, email, order_id, datetime, isbn, quantity, price):
self.email = email
self.order_id = order_id
......@@ -84,16 +84,15 @@ def authenticate(e, p):
@app.route('/')
def homepage():
count=0
return render_template('homepage.html', size=len(data['items']), data= data, currentBook=count)
return render_template('show_books.html', size=len(data['items']), data= data)
@app.route('/logout')
def logout():
if session['logged_in'] == True:
session['logged_in'] = False
return render_template('homepage.html',size=len(data['items']), data= data)
return render_template('show_books.html',size=len(data['items']), data= data)
else:
return render_template('homepage.html',size=len(data['items']), data= data)
return render_template('show_books.html',size=len(data['items']), data= data)
@app.route('/sign_up')
def signup():
......@@ -102,51 +101,74 @@ def signup():
@app.route('/show_books')
def show_books():
session['log_count']=len(CurrentCart.query.all())
return render_template('show_books.html', size=len(data['items']), data= data)
@app.route('/book/<int:id>/', methods=['GET','POST'])
def book(id):
flag=0
if request.method == 'GET':
session['log_count']=len(CurrentCart.query.all())
return render_template('book.html', id = id, data=data, flag=flag)
else:
quantity=request.form.get('comp_select')
book = str(data['items'][id]["volumeInfo"]["authors"][0])
book = str(data['items'][id]["volumeInfo"]["title"])
cart=CurrentCart(email=session['log_email'], datetime=datetime.datetime.now(),book=book , quantity=quantity, price=data['items'][id]["saleInfo"]["listPrice"]["amount"])
detail = CurrentCart.query.filter_by(book=book).all()
sum=0
for d in detail:
sum+=(d.__dict__["quantity"])
if sum+int(quantity)<3:
if sum+int(quantity)<4:
db.session.add(cart)
db.session.commit()
flag = 1
else:
flag = 2
session['log_count']=len(CurrentCart.query.all())
return render_template('book.html', id=id, data=data, flag=flag)
@app.route('/login',methods=['GET','POST'])
def login():
session['log_count']=len(CurrentCart.query.all())
error = None
if request.method == 'POST':
if(authenticate(request.form['username'], request.form['password'])):
session['logged_in'] = True
session['log_email'] = request.form['username']
flash("You are logged in")
return redirect(url_for('homepage'))
return redirect(url_for('show_books'))
else:
error='Invalid credentials'
return render_template('login.html', error=error)
@app.route('/cart',methods=['GET','POST'])
def cart():
# book = str(data['items'][id]["volumeInfo"]["authors"][0])
return render_template('cart.html',size=len(data['items']), data=data, items= CurrentCart.query.all())
session['log_count']=len(CurrentCart.query.all())
dp = CurrentCart.query.all()
sum=0
for d in dp:
sum+=(d.__dict__["price"])
return render_template('cart.html',size=len(data['items']), data=data, items= CurrentCart.query.all(),bill=sum)
@app.route('/show_orders',methods=['GET','POST'])
def show_orders():
session['log_count']=len(CurrentCart.query.all())
cartx = CurrentCart.query.all()
if len(cartx)>0:
for dx in cartx:
order = CustOrders(1,email=session['log_email'],order_id=112,datetime=datetime.datetime.now(),isbn=dx.__dict__["book"],quantity=dx.__dict__["quantity"],price=dx.__dict__["price"])
db.session.add(order)
db.session.commit()
return render_template('show_orders.html')
else:
error=" Sorry ! There should be something in cart to place order."
return render_template('show_orders.html',error=error)
@app.route('/clear_cart',methods=['GET'])
def clear_cart():
session['log_count']=len(CurrentCart.query.all())
total=0
cart_items= CurrentCart.query.all()
for cart_item in cart_items:
......@@ -157,7 +179,6 @@ def clear_cart():
with open("json/catalog.json") as data_file:
data = json.loads(data_file.read())
print(data['items'][0]['volumeInfo']['title'])
if __name__ == '__main__':
app.run(debug=True)
No preview for this file type
File added
{% extends "layout.html" %}
{% block body%}
<br></br>
<a href="/clear_cart"><button class="btn teal left">Clear Cart</button></a>
<a href="/clear_cart"><button class="btn teal left waves-effect">Clear Cart</button></a>
<table class="center">
<thead>
<th>Serail No</th>
......@@ -22,9 +22,21 @@
</tbody>
{% endfor %}
</table>
<br></br>
<br>
<h7 class="right"><b>Bill Amount:</b> ₹ {{ bill }}</h7>
</br>
<div>
<form><input type="text" name="name" placeholder="Name here..."><input type="text" name="phone" placeholder="Phone Number here..."></form><br>
<button class="btn teal right">₹ {{ bill }}<i class="fas fa-cart-plus"></i></button>
<form>
<div class="input-field col s6">
<input id="last_name" type="text" class="validate">
<label for="last_name">Name</label>
</div>
<div class="input-field col s6">
<input id="last_name" type="text" class="validate">
<label for="last_name">Password</label>
</div>
</form>
<br>
<a href="/show_orders"><button class="btn teal right">Proceed To Checkout<i class="fas fa-cart-plus"></i></button></a>
</div>
{% endblock %}
\ No newline at end of file
......@@ -4,9 +4,6 @@
<title>Book Shoppee</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.9/js/all.js" integrity="sha384-8iPTk2s/jMVj81dnzb/iFR2sdA7u06vHJyyLlAd4snFpCl/SnyUjRrbdJsw1pGIl" crossorigin="anonymous"></script>
......@@ -19,21 +16,20 @@
.item{
margin-bottom: 5%;
}
</style>
</head>
<body>
<nav class="nav-wrapper teal waves-effect">
<div class="container">
<a class="brand-logo text-uppercase" href="/show_books">BOOK SHOPPE</a>
<a class="brand-logo text-uppercase" href="/show_books"><i class="fas fa-book"></i> BOOK SHOPPE</a>
{% if not session.logged_in %}
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="#"><i class="fas fa-user-plus waves-effect"></i> Sign Up</a></li>
<!-- <li><a href="#"><i class="fas fa-user-plus waves-effect"></i> Sign Up</a></li> -->
<li><a href="/login"><i class="fas fa-sign-in-alt waves-effect"></i> Login</a></li>
</ul>
{% else %}
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="/cart"><i class="fas fa-shopping-cart waves-effect"></i> Cart</a></li>
<li><a href="/cart"><i class="fas fa-shopping-cart waves-effect"></i> Cart<span class="new badge deep-purple darken-4">{{ session.log_count }}</span></a></li>
<li><a href="/logout"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
</ul>
{% endif %}
......
{% extends 'layout.html' %}
{% block body %}
<center><h2 class="italic">Orders Page</h2></center>
{% if error %}
<center>
<h5>{{ error }}</h5>
<br>
<p style="font-size: 50px">🙆</p>
</center>
{% endif %}
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment