|
|
@ -123,7 +123,13 @@ def construct_object_from_request(cls: Type[StructuredNode], uid=None, data: dic
|
|
|
|
def handle_object_api_request(cls: Type[StructuredNode]):
|
|
|
|
def handle_object_api_request(cls: Type[StructuredNode]):
|
|
|
|
"""basic method for handling (GET|POST) /api/type calls"""
|
|
|
|
"""basic method for handling (GET|POST) /api/type calls"""
|
|
|
|
if request.method == 'GET':
|
|
|
|
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':
|
|
|
|
if request.method == 'POST':
|
|
|
|
obj, attach_relationships = construct_object_from_request(cls, data=request.get_json())
|
|
|
|
obj, attach_relationships = construct_object_from_request(cls, data=request.get_json())
|
|
|
|
obj.save()
|
|
|
|
obj.save()
|
|
|
|