From 1609d8ae29b71e6e05c7f02a7e8d394c63787e05 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)