From 46c41578e58f02fb871eca454ac670f215f3e0d5 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 25 Nov 2021 15:40:15 +0100 Subject: [PATCH] [utils] Add util to get pagination filter args from request --- flaschengeist/utils/HTTP.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/flaschengeist/utils/HTTP.py b/flaschengeist/utils/HTTP.py index 8fe57a9..e81316b 100644 --- a/flaschengeist/utils/HTTP.py +++ b/flaschengeist/utils/HTTP.py @@ -2,6 +2,24 @@ from http.client import NO_CONTENT, CREATED from flask import make_response, jsonify +from flaschengeist.utils.datetime import from_iso_format + + +def get_filter_args(): + """ + Get filter parameter from request + returns: FROM, TO, LIMIT, OFFSET, DESCENDING + """ + from flask import request + + return ( + request.args.get("from", type=from_iso_format), + request.args.get("to", type=from_iso_format), + request.args.get("limit", type=int), + request.args.get("offset", type=int), + "descending" in request.args, + ) + def no_content(): return make_response(jsonify(""), NO_CONTENT)