From 3da2ed53d5676dd6f4079c3a06ed5715480005e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 17 Apr 2021 18:27:14 +0200 Subject: [PATCH] [pricelist][#6] save order of pricelist columns for user --- flaschengeist/plugins/pricelist/__init__.py | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/flaschengeist/plugins/pricelist/__init__.py b/flaschengeist/plugins/pricelist/__init__.py index 68205ba..ef19807 100644 --- a/flaschengeist/plugins/pricelist/__init__.py +++ b/flaschengeist/plugins/pricelist/__init__.py @@ -567,6 +567,36 @@ def get_columns(userid, current_session): userController.persist() return no_content() +@PriceListPlugin.blueprint.route("/users//pricecalc_columns_order", methods=["GET", "PUT"]) +@login_required() +def get_columns_order(userid, current_session): + """Get pricecalc_columns_order of an user + + Route: ``/users//pricelist/pricecac_columns_order`` | Method: ``GET`` or ``PUT`` + POST-data: On ``PUT`` json encoded array of floats + + Args: + userid: Userid identifying the user + current_session: Session sent with Authorization Header + + Returns: + GET: JSON object containing the shortcuts as object array or HTTP error + PUT: HTTP-created or HTTP error + """ + if userid != current_session.user_.userid: + raise Forbidden + + user = userController.get_user(userid) + if request.method == "GET": + return jsonify(user.get_attribute("pricecalc_columns_order", [])) + else: + data = request.get_json() + if not isinstance(data, list) or not all(isinstance(n, str) for mop in data for n in mop.values()): + raise BadRequest + user.set_attribute("pricecalc_columns_order", data) + userController.persist() + return no_content() + @PriceListPlugin.blueprint.route("/users//pricelist", methods=["GET", "PUT"]) @login_required()