From 17faf87eeac8424223a87c779618dc8722286172 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Thu, 19 Nov 2020 13:43:58 +0100 Subject: [PATCH] api query parameters working --- server/abstract_api.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/abstract_api.py b/server/abstract_api.py index fcc72a3..e411e7a 100644 --- a/server/abstract_api.py +++ b/server/abstract_api.py @@ -123,7 +123,13 @@ def construct_object_from_request(cls: Type[StructuredNode], uid=None, data: dic def handle_object_api_request(cls: Type[StructuredNode]): """basic method for handling (GET|POST) /api/type calls""" if request.method == 'GET': - return jsonify([obj.json(include_relations=False) for obj in cls.nodes.all()]) + limit = request.args.get('$limit', 100, int) + offset = request.args.get('$offset', 0, int) + options = {k: v for k, v in request.args.items() if k[0] != '$'} + return jsonify([ + obj.json(include_relations=False) + for obj in cls.nodes.filter(**options).order_by('uid').all()[offset:offset+limit] + ]) if request.method == 'POST': obj, attach_relationships = construct_object_from_request(cls, data=request.get_json()) obj.save()