From b98bae337ddf602c5e1e176a455430ad7b8f09e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 21 Mar 2021 22:06:24 +0100 Subject: [PATCH] [pricelist] add modify settings, fixed update drinks --- flaschengeist/plugins/pricelist/__init__.py | 13 +++++++++++++ .../plugins/pricelist/pricelist_controller.py | 19 +++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/flaschengeist/plugins/pricelist/__init__.py b/flaschengeist/plugins/pricelist/__init__.py index cc3ec44..1d24715 100644 --- a/flaschengeist/plugins/pricelist/__init__.py +++ b/flaschengeist/plugins/pricelist/__init__.py @@ -179,6 +179,19 @@ def delete_extra_ingredient(identifier): return "", NO_CONTENT +@pricelist_bp.route("/settings/min_prices", methods=["POST", "GET"]) +def pricelist_settings_min_prices(): + if request.method == "GET": + return jsonify(PriceListPlugin.get_setting(PriceListPlugin, "min_prices")) + else: + data = request.get_json() + if not isinstance(data, list) or not all(isinstance(n, int) for n in data): + raise BadRequest + data.sort() + PriceListPlugin.set_setting(PriceListPlugin, "min_prices", data) + return no_content() + + @pricelist_bp.route("/users//pricecalc_columns", methods=["GET", "PUT"]) @login_required() def get_columns(userid, current_session: Session): diff --git a/flaschengeist/plugins/pricelist/pricelist_controller.py b/flaschengeist/plugins/pricelist/pricelist_controller.py index 1544d97..e739db1 100644 --- a/flaschengeist/plugins/pricelist/pricelist_controller.py +++ b/flaschengeist/plugins/pricelist/pricelist_controller.py @@ -128,25 +128,24 @@ def update_drink(identifier, data): allowedKeys = Drink().serialize().keys() if "id" in data: data.pop("id") - values = {key: value for key, value in data.items() if key in allowedKeys} - volumes = None - if "volumes" in values: - volumes = values.pop("volumes") - if "tags" in values: - values.pop("tags") + if "volumes" in data: + volumes = data.pop("volumes") + if "tags" in data: + data.pop("tags") type = None - if "type" in values: - _type = values.pop("type") + if "type" in data: + _type = data.pop("type") if isinstance(_type, dict) and "id" in _type: type = get_drink_type(_type.get("id")) if identifier == -1: - drink = Drink(**values) + drink = Drink() db.session.add(drink) else: drink = get_drink(identifier) if not drink: raise NotFound - for key, value in values.items(): + for key, value in data.items(): + if hasattr(drink, key): setattr(drink, key, value if value != "" else None) if type: