From e4b937991be4b363c9dd0cc34096bc6cc08b2842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 13 Nov 2021 15:44:06 +0100 Subject: [PATCH] [pricelist] add serverside pagination and filter for receipts --- flaschengeist/plugins/pricelist/__init__.py | 4 ++++ flaschengeist/plugins/pricelist/pricelist_controller.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/flaschengeist/plugins/pricelist/__init__.py b/flaschengeist/plugins/pricelist/__init__.py index 2239727..5ad57af 100644 --- a/flaschengeist/plugins/pricelist/__init__.py +++ b/flaschengeist/plugins/pricelist/__init__.py @@ -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}) diff --git a/flaschengeist/plugins/pricelist/pricelist_controller.py b/flaschengeist/plugins/pricelist/pricelist_controller.py index b32a26d..0b786a9 100644 --- a/flaschengeist/plugins/pricelist/pricelist_controller.py +++ b/flaschengeist/plugins/pricelist/pricelist_controller.py @@ -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))