43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from flask import Blueprint, redirect, render_template, request, session
|
|
|
|
|
|
from . import db
|
|
|
|
|
|
bp = Blueprint("entry", __name__, url_prefix="/entry")
|
|
|
|
|
|
@bp.get("/")
|
|
def index():
|
|
with db.run_query("entry/get_groups.sql") as cursor:
|
|
groups = cursor.fetchall()
|
|
|
|
with db.run_query("entry/get_locations.sql") as cursor:
|
|
locations = cursor.fetchall()
|
|
|
|
with db.run_query("entry/get_tax_groups.sql") as cursor:
|
|
tax_groups = cursor.fetchall()
|
|
|
|
return render_template("entry/index.html", **{
|
|
"locations": locations,
|
|
"groups": groups,
|
|
"tax_groups": tax_groups
|
|
})
|
|
|
|
@bp.get("/api/search-items")
|
|
def api_search_items():
|
|
try:
|
|
search_term = request.args["search-term"]
|
|
except:
|
|
return {"error": "Missing query parameter `search-term`"}, 400
|
|
|
|
location = session.get("location", None)
|
|
|
|
with db.run_query("search_items.sql", {
|
|
"location_id": None if location is None else location["location_id"],
|
|
"search_term": search_term
|
|
}) as cursor:
|
|
items = cursor.fetchall()
|
|
|
|
return items
|