api query parameters working

master
Anton Lydike 4 years ago
parent b3586a6708
commit 17faf87eea

@ -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()

Loading…
Cancel
Save