diff --git a/app.py b/app.py new file mode 100644 index 0000000..88a0f48 --- /dev/null +++ b/app.py @@ -0,0 +1,61 @@ +from flask import Flask +from flask import render_template # using render_template to have the html code in different files +from flask_sqlalchemy import SQLAlchemy # database library for flask +from flask_wtf import FlaskForm # form library for flask +from wtform import StringField, SubmitField #library form +from forms import RegisterForm #register form used to add books to the stock +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI']= 'sqlite:///books.db' #confgurating a database +app.config['SECRET_KEY']='f4e41413da3eb27b9fb55eda' #creating a secret key for addbook function +db = SQLAlchemy(app) + +#models +class User(db.Model): #creating a User class for the database that contains the user information + id = db.Column(db.Integer(), primary_key=1) #primary key for this database + username = db.Column(db.String(length=20), nullable=0, unique=1) + password = db.Column(db.String(length=20), nullable=0) + + +class Book(db.Model): #creating a book class for the database that contains the information about books for the store + barcode = db.Column(db.String(length=12), nullable=0, primary_key=1) # setting the ISBN 13 number as the primary key for the database + title = db.Column(db.String(length=50), nullable=0, unique=1) + author = db.Column(db.String(length=50), nullable=0) + publicationDate = db.Column(db.String(length=10), nullable=0) + quantity = db.Column(db.Integer(), nullable=0) + description = db.Column(db.String(length=1000), nullable=0) + tradePrice = db.Column(db.String(length=10), nullable=0) + retailPrice = db.Column(db.String(length=10), nullable=0) + + +#routes +@app.route("/login") #route for login page +def login_page(): + return render_template("login.html") + + +@app.route("/home") #route home page +@app.route("/") #added to routes for the default page and when /home is added +def home_page(): + return render_template("home.html") +@app.route("/stock") +def stock_page(): #route to the page showing all the available books + books=Book.query.all() + return render_template("stock.html", books=books) + +@app.route("/addstock") +def addStock_page(): # route to the page for adding books to the database + form = RegisterForm() #using jinja to send the register form to the website + return render_template('addstock.html', form=form) + +#forms + +class AddBook(FlaskForm): # class created to add more books used on the add stock page + barcode = StringField(label='barcode') + title = StringField(label='title') + author = StringField(label='author') + publicationDate = StringField(label=' Publication Date') + quantity = StringField(label=' quantity') + description = StringField(label='description') + tradePrice = StringField(label='Trade Price') + retailPrice = StringField(label='Retail Price') + submit = SubmitField(label='submit') #submit field