Commit 8fa24dc3 authored by Joel's avatar Joel
Browse files

Initial commit

parents
from flask import Flask, request, session, redirect, url_for, abort, render_template, flash
from flask_sqlalchemy import SQLAlchemy
from flask_material import Material
import datetime
from sqlalchemy import Table
import json
app = Flask(__name__)
Material(app)
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:///booksmart.db'
db=SQLAlchemy(app)
class Login(db.Model):
# __tablename__ = 'users'
email = db.Column(db.String(100), primary_key=True)
password = db.Column(db.String(240))
def __init__(self, email, password,):
self.email = email
self.password = password
def __repr__(self):
return '<Entry %r %r %r %r>' % (self.email, self.password,)
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))
datetime = db.Column(db.DateTime)
isbn=db.Column(db.String(20))
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
self.datetime = datetime
self.isbn = isbn
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)
class CurrentCart(db.Model):
# __tablename__ = 'users'
serial = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(100), db.ForeignKey('login.email'))
isbn = db.Column(db.String(20))
quantity = db.Column(db.Integer)
price = db.Column(db.Integer)
def __init__(self, email, datetime, isbn, quantity, price):
self.email = email
self.isbn = isbn
self.quantity = quantity
self.price = price
def __repr__(self):
return '<Entry %r %r %r %r>' % (
self.email, self.isbn, self.quantity, self.price)
# Create the table
db.create_all()
def authenticate(e, p):
print(e)
details=Login.query.filter_by(email=e).filter_by(password=p).all()
print(details)
if(len(details)>0):
return True
else:
return False
@app.route('/')
def homepage():
return render_template('homepage.html', size=len(data['items']), data= data)
@app.route('/book/<int:id>/', methods=['GET','POST'])
def book(id):
flag=0
if request.method == 'GET':
return render_template('book.html', id = id, data=data, flag=flag)
else:
quantity=request.form.get('comp_select')
isbn = 'ISBN' + str(data['items'][id]["volumeInfo"]["industryIdentifiers"][0]["identifier"])
cart=CurrentCart(email=session['log_email'], datetime=datetime.datetime.now(),isbn=isbn , quantity=quantity, price=data['items'][id]["saleInfo"]["listPrice"]["amount"])
detail = CurrentCart.query.filter_by(isbn=isbn).all()
sum=0
for d in detail:
sum+=(d.__dict__["quantity"])
if sum+int(quantity)<3:
db.session.add(cart)
db.session.commit()
flag = 1
else:
flag = 2
return render_template('book.html', id=id, data=data, flag=flag)
@app.route('/login',methods=['GET','POST'])
def login():
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'))
else:
error='Invalid credentials'
return render_template('login.html', error=error)
@app.route('/cart',methods=['GET'])
def cart():
# lst = CurrentCart.query.filter_by(isbn=isbn).all()
# print(lst)
return render_template('cart.html',size=len(data['items']), data=data)
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)
File added
This diff is collapsed.
{% extends "layout.html" %}
{% block body %}
<div class="row container-fluid" style="margin-top: 5%">
<div class="col s2">
<img class="book_image img-responsive hoverable" src="{{ data['items'][id]["volumeInfo"]["imageLinks"]["thumbnail"] }}" alt="image">
</div>
<div class="col s6">
<h4><b>{{ data['items'][id]["volumeInfo"]["title"] }}</b></h4>
<i class="flow-text"><i class="fas fa-user"></i> {{ data['items'][id]["volumeInfo"]["authors"][0] }}</i>
<i><h6><b>ISBN :</b> {{ data['items'][id]["volumeInfo"]["industryIdentifiers"][0]["identifier"] }}</h6></i>
<p class="">{{ data['items'][id]["volumeInfo"]["description"] }}</p>
<h6><strong>Page Count:</strong>{{ data['items'][id]["volumeInfo"]["pageCount"] }}</h6>
</div>
<div class="col s1"></div>
<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>
<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>
</div>
<p>Exclusive of all taxes</p>
<h6 style="color: green">In Stock</h6>
{% if session.logged_in %}
<input type="submit" name="addtocart" class="btn-small waves-effect" style="width: 100%; margin-bottom: 5%;" value="Add to Cart">
{% if flag==1 %}
<div class="alert alert-success" >
<strong>Successfully added to Cart</strong>
</div>
{% elif flag == 2 %}
<div class="alert alert-danger">
<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">
{% 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>
{% endif %}
{% else %}
<p>Not available</p>
{% endif %}
</form>
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends "layout.html" %}
{% block body%}
<br></br>
{% for i in range((size)//2) %}
<ul class="collection hoverable">
<li class="collection-item ">
<i class="material-icons circle"></i>
<b class="title text-lighten-5">{{ data['items'][i]["volumeInfo"]["title"] }}</b>
<p>{{ data['items'][i]["volumeInfo"]["authors"][0] }}</p>
<a href="#!" class="secondary-content"><i class="fas fa-plus-circle" style="font-size:30px"></i></a>
</li>
</ul>
{% endfor %}
<button class="btn teal right"><i class="fas fa-cart-plus"></i> Proceed to Checkout</button>
{% endblock %}
\ No newline at end of file
{% extends "layout.html" %}
{% block body %}
<h4 style="margin-bottom: 5%;text-align: center"><b>CATALOG</b></h4>
<style>
.card-adjust{
height: 420px;
overflow: hidden;
}
</style>
<div class="row container">
{% with currentBook=1 %}
<center class="col s3 h-100 waves-effect" style="margin-top: 30%;"><button class="btn waves-effect" id="prevBtn" style="border-radius: 50%" onclick="prev()"><i class="fas fa-caret-left"></i></button></center>
<div class="col s6 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" >
<h5 class="card-title">
<a href="book/{{ currentBook }}"> {{ data['items'][currentBook]["volumeInfo"]["title"] }}</a>
</h5>
<p href="book/{{ currentBook }}"><i class="fas fa-user"></i> {{ data['items'][currentBook]["volumeInfo"]["authors"][0] }}</p>
<p href="book/{{ currentBook }}"><i class="fas fa-tag"></i> {{ data['items'][currentBook]["volumeInfo"]["categories"][0]}}</p>
</blockquote>
</div>
</div>
<center class="col s3 h-100 waves-effect" style="margin-top: 30%"><button class="btn waves-effect" id="nextBtn" style="border-radius: 50%" onclick=""><i class="fas fa-caret-right"></i></button></center>
{% endwith %}
</div>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<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>
<style>
.dp{
width: 40%;
height: 179px;
}
.item{
margin-bottom: 5%;
}
@font-face {
font-family: Montserrat-Regular;
src: url(/Montserrat-Regular.otf);
}
body{
font-family: Montserrat-Regular;
}
.badge {
display: inline-block;
padding: 0.25em 0.4em;
font-size: 75%;
font-weight: 700;
line-height: 1;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: 0.25rem;
}
.badge:empty {
display: none;
}
.btn .badge {
position: relative;
top: -1px;
}
.badge-pill {
padding-right: 0.6em;
padding-left: 0.6em;
border-radius: 10rem;
}
.badge-primary {
color: #fff;
background-color: #007bff;
}
</style>
</head>
<body>
<nav class="nav-wrapper teal waves-effect">
<div class="container">
<a class="brand-logo text-uppercase" href="/">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="/login"><i class="fas fa-signin-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="#"><i class="fas fa-user waves-effect"></i> User</a></li>
</ul>
{% endif %}
</div>
</nav>
<div class="container" >
{% block body %}
{% endblock %}
</div>
<!-- {% block footer %}
<center>Created by: Joel Vinay Kumar</center>
{% endblock %} -->
</body>
</html>
\ No newline at end of file
{% extends "layout.html" %}
{% block body %}
<center>
<h2 class="text-center"><b>LOGIN</b></h2>
</center>
{% if error %}
<p class="error"><strong>Error:</strong> {{ error }}{% endif %}
<form action="{{ url_for('login') }}" 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 id="txtUser" type="text" class="form-control" name="username" placeholder="Username">
</div>
<div class="input-group">
<span class="input-group-addon"></span>
<input id="txtPassword" type="password" class="form-control" name="password" placeholder="Password">
</div><br>
<center><input class="btn btn-small" type="submit" value="SIGN IN"></input></center>
</form>
</div>
</div>
</div>
</form>
<style>
body {
background: white no-repeat;
}
.login-form{width:390px;}
/*.login-title{font-family: 'Exo', sans-serif;text-align:center;color: white;}*/
.login-userinput{margin-bottom: 10px;}
.login-button{margin-top:10px;}
.login-options{margin-bottom:0px;}
.login-forgot{float: right;}
</style>
{% endblock %}
\ No newline at end of file
document.getElementById('name').innerHTML = "Joel Vinay Kumar";
document.getElementById('email').innerHTML = "[email protected]";
\ 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