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

Initial commit

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__)
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'
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,): = email
self.password = password
def __repr__(self):
return '<Entry %r %r %r %r>' % (, self.password,)
class CustOrders(db.Model):
# __tablename__ = 'users'
serial = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(100), db.ForeignKey(''))
order_id = db.Column(db.String(100))
datetime = db.Column(db.DateTime)
def __init__(self, serial, email, order_id, datetime, isbn, quantity, price): = 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.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(''))
isbn = db.Column(db.String(20))
quantity = db.Column(db.Integer)
price = db.Column(db.Integer)
def __init__(self, email, datetime, isbn, quantity, price): = email
self.isbn = isbn
self.quantity = quantity
self.price = price
def __repr__(self):
return '<Entry %r %r %r %r>' % (, self.isbn, self.quantity, self.price)
# Create the table
def authenticate(e, p):
return True
return False
def homepage():
return render_template('homepage.html', size=len(data['items']), data= data)
@app.route('/book/<int:id>/', methods=['GET','POST'])
def book(id):
if request.method == 'GET':
return render_template('book.html', id = id, data=data, flag=flag)
isbn = 'ISBN' + str(data['items'][id]["volumeInfo"]["industryIdentifiers"][0]["identifier"])
cart=CurrentCart(email=session['log_email'],,isbn=isbn , quantity=quantity, price=data['items'][id]["saleInfo"]["listPrice"]["amount"])
detail = CurrentCart.query.filter_by(isbn=isbn).all()
for d in detail:
if sum+int(quantity)<3:
flag = 1
flag = 2
return render_template('book.html', id=id, data=data, flag=flag)
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'))
error='Invalid credentials'
return render_template('login.html', error=error)
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(
if __name__ == '__main__':
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 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 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 %}
<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>
{% elif flag == 2 %}
<div class="alert alert-danger">
<strong>Cart Limit Exceeded</strong>
{% 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 %}
{% endblock %}
\ No newline at end of file
{% extends "layout.html" %}
{% block body%}
{% 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>
{% 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>
height: 420px;
overflow: hidden;
<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>
<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>
<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 %}
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<title>Book Shoppee</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script> -->
<link rel="stylesheet" href="">
<script src=""></script>
<script defer src="" integrity="sha384-8iPTk2s/jMVj81dnzb/iFR2sdA7u06vHJyyLlAd4snFpCl/SnyUjRrbdJsw1pGIl" crossorigin="anonymous"></script>
width: 40%;
height: 179px;
margin-bottom: 5%;
@font-face {
font-family: Montserrat-Regular;
src: url(/Montserrat-Regular.otf);
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;
<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>
{% 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>
{% endif %}
<div class="container" >
{% block body %}
{% endblock %}
<!-- {% block footer %}
<center>Created by: Joel Vinay Kumar</center>
{% endblock %} -->
\ No newline at end of file
{% extends "layout.html" %}
{% block body %}
<h2 class="text-center"><b>LOGIN</b></h2>
{% 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">
<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 class="input-group">
<span class="input-group-addon"></span>
<input id="txtPassword" type="password" class="form-control" name="password" placeholder="Password">
<center><input class="btn btn-small" type="submit" value="SIGN IN"></input></center>
body {
background: white no-repeat;
/*.login-title{font-family: 'Exo', sans-serif;text-align:center;color: white;}*/
.login-userinput{margin-bottom: 10px;}
.login-forgot{float: right;}
{% 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