Skip to content
Snippets Groups Projects
Commit 22d871ef authored by Eva Bardou's avatar Eva Bardou Committed by Bastien Abadie
Browse files

Add generic function create_sub_element()

parent fbb412bd
No related branches found
Tags 0.1.9
Loading
......@@ -148,3 +148,39 @@ class ElementsWorker(BaseWorker):
def process_element(self, element):
"""Override this method to analyze an Arkindex element from the provided list"""
def create_sub_element(self, element, type, name, polygon):
"""
Create a child element on the given element through API
"""
assert element and isinstance(
element, Element
), "element shouldn't be null and should be of type Element"
assert type and isinstance(
type, str
), "type shouldn't be null and should be of type str"
assert name and isinstance(
name, str
), "name shouldn't be null and should be of type str"
assert polygon and isinstance(
polygon, list
), "polygon shouldn't be null and should be of type list"
assert len(polygon) >= 3, "polygon should have at least three points"
assert all(
isinstance(point, list) and len(point) == 2 for point in polygon
), "polygon points should be lists of two items"
assert all(
isinstance(coord, (int, float)) for point in polygon for coord in point
), "polygon points should be lists of two numbers"
self.api_client.request(
"CreateElement",
body={
"type": type,
"name": name,
"image": element.zone.image.id,
"corpus": element.corpus.id,
"polygon": polygon,
"parent": element.id,
},
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment