Add search box for location to quantities page

This commit is contained in:
BBaoVanC 2020-10-05 23:16:36 -05:00
parent 82f37f4b25
commit df6e64afc3
No known key found for this signature in database
GPG Key ID: 6D74C8B0E7D791C2
2 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,11 @@
<!DOCTYPE HTML>
<html>
<body>
<form action="./quantities">
<input type="text" placeholder="Location" name="location" />
<input type="submit" />
</form>
<a href="./quantities">Clear Search</a>
<table border=1>
<tr>
<th>UPC</th>

View File

@ -6,7 +6,7 @@ Web User Interface for InvMan
"""
# Imports
from flask import Flask, render_template
from flask import Flask, render_template, request
from libdb import Session, Product, ProductQuantity
@ -28,6 +28,15 @@ def products_list_page():
def products_quantities_page():
"""Route for the quantities page"""
session = Session()
data = session.query(ProductQuantity.product_upc,
ProductQuantity.quantity, ProductQuantity.location).all()
return render_template("ui/quantities.html", data=data)
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)