Commit 9d94b061 authored by Joel's avatar Joel
Browse files

Pre final Commit

parent c7f096a9
......@@ -14,7 +14,7 @@ app.config['DEBUG'] = True
app.config['SECRET_KEY'] ='super-secret-key'
app.config['USERNAME'] = 'admin'
app.config['PASSWORD'] = '12345'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///bookshoppe.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///bookshopper.db'
db=SQLAlchemy(app)
......@@ -36,26 +36,26 @@ class CustOrders(db.Model):
email = db.Column(db.String(100), db.ForeignKey('login.email'))
order_id = db.Column(db.Integer)
datetime = db.Column(db.DateTime)
isbn=db.Column(db.String)
book=db.Column(db.String(100))
quantity=db.Column(db.Integer)
price=db.Column(db.Integer)
def __init__(self, serial, email, order_id, datetime, isbn, quantity, price):
def __init__(self, serial, email, order_id, datetime, book, quantity, price):
self.email = email
self.order_id = order_id
self.datetime = datetime
self.isbn = isbn
self.book = book
self.quantity = quantity
self.price = price
def __repr__(self):
return '<Entry %r %r %r %r %r %r>' % (self.email, self.order_id, self.datetime, self.isbn, self.quantity, self.price)
return '<Entry %r %r %r %r %r %r>' % (self.email, self.order_id, self.datetime, self.book, self.quantity, self.price)
class CurrentCart(db.Model):
# __tablename__ = 'users'
serial = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(100), db.ForeignKey('login.email'))
book = db.Column(db.String(20))
book = db.Column(db.String(100))
quantity = db.Column(db.Integer)
price = db.Column(db.Integer)
......@@ -84,7 +84,7 @@ def authenticate(e, p):
@app.route('/')
def homepage():
return render_template('show_books.html', size=len(data['items']), data= data)
return render_template('homepage.html', size=len(data['items']), data= data)
@app.route('/logout')
def logout():
......@@ -94,9 +94,19 @@ def logout():
else:
return render_template('show_books.html',size=len(data['items']), data= data)
@app.route('/sign_up')
def signup():
return render_template('sign_up.html')
@app.route('/sign_up',methods=['GET','POST'])
def sign_up():
error = None
if request.method== 'GET':
return render_template('sign_up.html')
else:
uname = request.form.get('uname')
pwd = request.form.get('pwd')
new_user = Login(uname,pwd)
db.session.add(new_user)
db.session.commit()
flash("Your account has been saved. Please save your creentials")
return render_template('sign_up.html')
@app.route('/show_books')
......@@ -111,7 +121,6 @@ def book(id):
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"]["title"])
cart=CurrentCart(email=session['log_email'], datetime=datetime.datetime.now(),book=book , quantity=quantity, price=data['items'][id]["saleInfo"]["listPrice"]["amount"])
......@@ -145,27 +154,50 @@ def login():
@app.route('/cart',methods=['GET','POST'])
def cart():
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)
if request.method == 'GET':
session['log_count']=len(CurrentCart.query.all())
dp = CurrentCart.query.all()
sum=0
for d in dp:
sum+=((d.__dict__["price"])*(d.__dict__["quantity"]))
bill = sum + sum//10
tax = sum//10
session['log_count']=len(CurrentCart.query.all())
return render_template('cart.html',size=len(data['items']), data=data, items= CurrentCart.query.all(),bill=bill,tax=tax)
if request.method == 'POST':
c_name = request.form['cus_name']
c_phone = request.form['cus_phone']
orders =[]
order_no=1
@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:
global orders
global order_no
cart_collection = []
if session['log_count']>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"])
order = CustOrders(1,email=session['log_email'],order_id=order_no,datetime=datetime.datetime.now(),book=dx.book,quantity=dx.quantity,price=dx.price)
cart_collection.append(order)
db.session.add(order)
db.session.commit()
return render_template('show_orders.html')
order_no+=1
orders.append(cart_collection)
for x in orders:
print(x)
for cart_item in cartx:
db.session.delete(cart_item)
db.session.commit()
session['log_count']=len(CurrentCart.query.all())
return render_template('show_all_orders.html',all_orders=orders)
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())
......@@ -175,6 +207,7 @@ def clear_cart():
db.session.delete(cart_item)
db.session.commit()
flash("You just cleared the cart!!")
session['log_count']=len(CurrentCart.query.all())
return render_template('cart.html',size=len(data['items']), data=data, items= CurrentCart.query.all(),total=total)
with open("json/catalog.json") as data_file:
......
No preview for this file type
File added
No preview for this file type
......@@ -16,19 +16,25 @@
<div class="col s3">
<form method="POST" action="">
{% if not 'NOT_FOR_SALE' in data['items'][id]['saleInfo']['saleability'] %}
<h6><i class="fas fa-rupee-sign"></i> {{ data['items'][id]["saleInfo"]["listPrice"]["amount"] }}</h6>
<h6><i class="fas fa-rupee-sign"></i> {{ data['items'][id]["saleInfo"]["listPrice"]["amount"] }}</h6><br>
<div class="input-group">
<span class="input-group-addon"><strong>Quantity</strong></span>
<select name="comp_select" >
{% for o in range(1,4) %}
<option value="{{ o }}">{{ o }}</option>
{% endfor %}
</select>
<label>Select Quantity</label>
<input type="number" name="comp_select" min="1" max="3" class="validate"></input>
</div>
<p>Exclusive of all taxes</p>
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<p>Exclusive of all taxes</p>
{% if flag == 2 %}
<h6 style="color: red">Out of Stock</h6>
{% else %}
<h6 style="color: green">In Stock</h6>
{% endif %}
{% if session.logged_in %}
<input type="submit" name="addtocart" class="btn-small waves-effect" style="width: 100%; margin-bottom: 5%;" value="Add to Cart">
<input type="submit" name="addtocart" class="btn-small waves-effect" style="width: 100%; margin-bottom: 5%;" onclick="Materialize.toast("Added to Cart",3000)" value="Add to Cart">
{% if flag==1 %}
<div class="alert alert-success" >
<strong>Successfully added to Cart</strong>
......@@ -38,7 +44,7 @@
<strong>Cart Limit Exceeded</strong>
</div>
{% endif %}
<input type="submit" name="proceedtocheckout" class="btn btn-small waves-effect" style="width: 100%" value="Proceed to Checkout">
<a href="/cart" name="proceedtocheckout" class="btn btn-small waves-effect" style="width: 100%" value="Proceed to Checkout">Proceed To Checkout</a>
{% else %}
<a href="{{ url_for('login') }}"><button type="button" name="addtocart" class="btn btn-warning" style="width: 100%; margin-bottom: 5%;" value="Add to Cart"> Add to Cart</button></a>
<a href="{{ url_for('login') }}"><button type="button" name="proceedtocheckout" class="btn btn-success" style="width: 100%" value="Proceed to Checkout"><span class="glyphicon glyphicon-plus-sign"></span> Proceed to Checkout</button></a>
......
{% extends "layout.html" %}
{% block body%}
<br></br>
<a href="/clear_cart"><button class="btn teal left waves-effect">Clear Cart</button></a>
<table class="center">
<a href="/clear_cart"><button class="btn red left waves-effect">Clear Cart<i class="fas fa-trash"></i></button></a>
<table class="center highlight responsive-table">
<thead>
<th>Serail No</th>
<th>Username</th>
<th>ISBN</th>
<th>Book Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Price/book</th>
</thead>
{% for item in items %}
<tbody>
......@@ -23,20 +23,25 @@
{% endfor %}
</table>
<br>
<h7 class="right"><b>Bill Amount:</b> ₹ {{ bill }}</h7>
</br>
<div>
<form>
<div class="input-field col s6">
<input id="last_name" type="text" class="validate">
<label for="last_name">Name</label>
<div class="right">
<h7 class="right"><b>Bill Amount:</b> ₹ {{ '%0.2f' % bill }}</h7><br>
<p class="right" style="font-size:11px">[Includes Tax of 10% = ₹ {{ tax }}]</p>
</div>
</br></br></br>
<div class="row">
<form method="post">
<div class="input-field col s3">
<i class="material-icons prefix">account_circle</i>
<input name="cus_name" type="text" class="validate">
<label >Name</label>
</div>
<div class="input-field col s6">
<input id="last_name" type="text" class="validate">
<label for="last_name">Password</label>
<div class="input-field col s3">
<i class="material-icons prefix">phone</i>
<input name="cus_phone" type="text" class="validate">
<label >Phone</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>
<a href="/show_orders"><button class="btn teal right">Place The Order<i class="fas fa-cart-plus"></i></button></a>
</div>
{% endblock %}
\ No newline at end of file
......@@ -5,26 +5,41 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<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>
<style>
.dp{
width: 40%;
height: 179px;
height: 10px;
}
.item{
margin-bottom: 5%;
margin-bottom: 20%;
}
body {
display: flex;
min-height: 2vh;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
.copy{
border-width:0;width: auto;height: auto;max-height: 20px;
}
.fork{
border-width:0;width: auto;height: auto;max-height: 50px;
}
</style>
</head>
<body>
<nav class="nav-wrapper teal waves-effect">
<div class="container">
<a class="brand-logo text-uppercase" href="/show_books"><i class="fas fa-book"></i> BOOK SHOPPE</a>
<a class="brand-logo text-uppercase" href="/show_books"><i class="material-icons prefix">class</i>Book Shopper</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="/sign_up"><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 %}
......@@ -39,8 +54,26 @@
{% block body %}
{% endblock %}
</div>
<!-- {% block footer %}
<center>Created by: Joel Vinay Kumar</center>
{% endblock %} -->
<footer class="teal waves-effect">
<div class="container">
<div class="row">
<div class="col l6 s12">
<h5 class="white-text"><b>Book Shoppr</b></h5>
<p class="grey-text text-lighten-4">This tiny e-commerce project is developed using Flask <3.</p>
<p class="grey-text text-lighten-4">This project is licensed under <a rel="license" href="https://www.gnu.org/licenses/gpl-3.0.en.html"><img alt="Creative Commons License" class="copy" src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/AGPLv3_Logo.svg/1200px-AGPLv3_Logo.svg.png" /></a></p>
</div>
<div class="col l4 offset-l2 s12">
<h5 class="white-text">Project Done by:</h5>
<ul>
<li><a class="grey-text text-lighten-3" href="https://joelvinaykumar.github.io">Joel Vinay Kumar</a></li>
<li><a class="grey-text text-lighten-3" href="#!">Uday Karthik</a></li>
<a href="https://code.swecha.org/joelvinaykumar/flask-book-shoppe"><img src="https://i1.wp.com/struscode.com/wp-content/uploads/2017/08/head-from-gitlab-logo-small-min.png?resize=256%2C250&ssl=1" class="fork"></a>
</ul>
</div>
</div>
</div>
</footer>
</body>
</html>
\ No newline at end of file
......@@ -10,13 +10,19 @@
<div class="panel panel-default">
<div class="panel-body">
<form>
<div class="input-group login-userinput">
<span class="input-group-addon"></span>
<input class="form-control" type="text" name="username" placeholder="Username">
<div class="input-field col s6">
<!-- <i class="material-icons prefix">account_circle</i>
<input class="form-control" type="text" name="username" placeholder="Username"> -->
<i class="material-icons prefix">account_circle</i>
<input id="last_name" type="text" class="validate" name="username">
<label for="last_name">Name</label>
</div>
<div class="input-group">
<span class="input-group-addon"></span>
<input class="form-control" type="password" name="password" placeholder="Password">
<div class="input-field col s6">
<!-- <i class="material-icons prefix">edit</i>
<input class="form-control" type="password" name="password" placeholder="Password"> -->
<i class="material-icons prefix">vpn_key</i>
<input id="last_name" type="password" class="validate" name="password">
<label for="last_name">Password</label>
</div><br>
<center><input class="btn btn-small" type="submit" value="Sign In"></input></center>
</form>
......
{% extends 'layout.html' %}
{% block body %}
<center>
<h4 class="italic"><i>Thank you for placing order with us, Joel!</i></h4>
<h6><i>Our delivery associate will contact you on 8801156293</i></h6>
</center>
{% for each_order in all_orders %}
<ul class="collection with-header">
<li class="collection-header"><h5>Order</h5></li>
{% for each in each_order %}
<li class="collection-item avatar">
<i class="material-icons circle blue">book</i>
<span class="title">{{ each.book }}</span>
{% if each.quantity==1 %}
<p>{{ each.quantity }} book<br>
{% elif each.quantity>1 %}
<p>{{ each.quantity }} books<br>
{% endif %}
<i>₹ {{ each.price }} each</i>
</p>
<a href="#!" class="secondary-content"><i class="material-icons">trash</i></a>
</li>
{% endfor %}
</ul>
{% endfor %}
{% if error %}
<center>
<h5>{{ error }}</h5>
<br>
<p style="font-size: 150px">🙆</p>
</center>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -3,13 +3,13 @@
<h4 style="margin-bottom: 5%;text-align: center"><b>SHOW BOOKS</b></h4>
<style>
.card-adjust{
height: 420px; /* Your height here */
height: 420px;
overflow: hidden;
}
</style>
<div class="row container">
{% for currentBook in range(size) %}
<div class="col s6 m6 ">
<div class="col s12 m6 ">
<div class="card-panel card-adjust">
<center><img class="card-image hoverable" src="{{ data['items'][currentBook]['volumeInfo']['imageLinks']['thumbnail'] }}" alt="book"></center>
<blockquote class="card-body left" >
......
......@@ -3,29 +3,31 @@
<br></br><br></br>
<center>
<h4 class="text-center"><b>CREATE YOUR ACCOUNT</b></h4>
</center>
</center><br>
{% if error %}
<p class="error"><strong>Error:</strong> {{ error }}{% endif %}
<form action="{{ url_for('login') }}" method="post">
<form action="{{ url_for('sign_up') }}" method="post">
<div class="container login-form">
<div class="panel panel-default">
<div class="panel-body">
<form>
<div class="input-group login-userinput">
<span class="input-group-addon"></span>
<input class="form-control" type="text" name="uname" placeholder="Write your Username...">
<div class="input-field col s6">
<i class="material-icons prefix">account_circle</i>
<input id="last_name" type="text" class="validate" name="uname">
<label for="last_name">Name</label>
</div>
<div class="input-group">
<span class="input-group-addon"></span>
<input class="form-control" type="password" name="pwd" placeholder="Write your Password...">
<div class="input-field col s6">
<i class="material-icons prefix">phone</i>
<input id="last_name" type="password" class="validate" name="pwd">
<label for="last_name">Password</label>
</div><br>
<center><input class="btn btn-small" type="submit" value="Sign In"></input></center>
<center><input class="btn btn-small" type="submit" value="Sign Up"></input></center>
</form>
</div>
</div>
</div>
</form>
<br><br>
<style>
body {
background: white no-repeat;
......
orders =[]
mini_order= []
mini_order.append(1)
mini_order.append(2)
mini_order.append(3)
mini_order.append(4)
orders.append(mini_order)
print(orders[0])
\ 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