[pricelist] add serverside pagination and filter for receipts
This commit is contained in:
parent
526433afba
commit
e4b937991b
|
@ -221,6 +221,7 @@ def get_drinks(identifier=None):
|
|||
search_name = request.args.get("search_name")
|
||||
search_key = request.args.get("search_key")
|
||||
ingredient = request.args.get("ingredient", type=bool)
|
||||
receipt = request.args.get("receipt", type=bool)
|
||||
try:
|
||||
if limit is not None:
|
||||
limit = int(limit)
|
||||
|
@ -228,6 +229,8 @@ def get_drinks(identifier=None):
|
|||
offset = int(offset)
|
||||
if ingredient is not None:
|
||||
ingredient = bool(ingredient)
|
||||
if receipt is not None:
|
||||
receipt = bool(receipt)
|
||||
except ValueError:
|
||||
raise BadRequest
|
||||
drinks, count = pricelist_controller.get_drinks(
|
||||
|
@ -237,6 +240,7 @@ def get_drinks(identifier=None):
|
|||
search_name=search_name,
|
||||
search_key=search_key,
|
||||
ingredient=ingredient,
|
||||
receipt=receipt,
|
||||
)
|
||||
logger.debug(f"GET drink {drinks}, {count}")
|
||||
# return jsonify({"drinks": drinks, "count": count})
|
||||
|
|
|
@ -131,7 +131,9 @@ def _create_public_drink(drink):
|
|||
return None
|
||||
|
||||
|
||||
def get_drinks(name=None, public=False, limit=None, offset=None, search_name=None, search_key=None, ingredient=False):
|
||||
def get_drinks(
|
||||
name=None, public=False, limit=None, offset=None, search_name=None, search_key=None, ingredient=False, receipt=None
|
||||
):
|
||||
count = None
|
||||
if name:
|
||||
query = Drink.query.filter(Drink.name.contains(name))
|
||||
|
@ -139,6 +141,8 @@ def get_drinks(name=None, public=False, limit=None, offset=None, search_name=Non
|
|||
query = Drink.query
|
||||
if ingredient:
|
||||
query = query.filter(Drink.cost_per_volume >= 0)
|
||||
if receipt:
|
||||
query = query.filter(Drink.volumes.any(DrinkPriceVolume.ingredients != None))
|
||||
if search_name:
|
||||
if search_key == "name":
|
||||
query = query.filter(Drink.name.contains(search_name))
|
||||
|
|
Loading…
Reference in New Issue