InvMan/webui.py

82 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""
InvMan Web UI
Web User Interface for InvMan
"""
# Imports
from flask import Flask, render_template, request
from libdb import Session, Product, ProductQuantity, Purchase, Use
app = Flask(__name__) # app is the Flask app
@app.route("/ui/products")
def products_list_page():
"""Route for the products page"""
session = Session()
data = session.query(
Product.upc, Product.brand, Product.name,
Product.size, Product.sizeunit, Product.description).all()
return render_template("ui/products.html", data=data)
@app.route("/ui/quantities")
def products_quantities_page():
"""Route for the quantities page"""
session = Session()
query = session.query(ProductQuantity.product_upc,
ProductQuantity.quantity, ProductQuantity.location)
if "location" in request.args:
searchloc = request.args['location']
if len(request.args['location']) > 0:
data = query.filter(ProductQuantity.location ==
request.args['location']).all()
else:
data = query.all()
else:
searchloc = ""
data = query.all()
return render_template("ui/quantities.html", data=data, searchloc=searchloc)
@app.route("/ui/purchases")
def products_purchases_page():
"""Route for the purchases page"""
session = Session()
query = session.query(Purchase.id, Purchase.product_upc,
Purchase.quantity, Purchase.date, Purchase.location)
if "location" in request.args:
searchloc = request.args['location']
if len(request.args['location']) > 0:
data = query.filter(Purchase.location ==
request.args['location']).all()
else:
data = query.all()
else:
searchloc = ""
data = query.all()
return render_template("ui/purchases.html", data=data, searchloc=searchloc)
@app.route("/ui/uses")
def products_uses_page():
"""Route for the uses page"""
session = Session()
query = session.query(Use.id, Use.product_upc,
Use.quantity, Use.date, Use.location)
if "location" in request.args:
searchloc = request.args['location']
if len(request.args['location']) > 0:
data = query.filter(Use.location ==
request.args['location']).all()
else:
data = query.all()
else:
searchloc = ""
data = query.all()
return render_template("ui/uses.html", data=data, searchloc=searchloc)