Skip to content
Snippets Groups Projects
Commit e50c3d93 authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'create-sub-element' into 'master'

Add generic function create_sub_element()

Closes #4

See merge request arkindex/base-worker!2
parents fbb412bd 22d871ef
No related branches found
No related tags found
1 merge request!2Add generic function create_sub_element()
Pipeline #77844 passed
...@@ -148,3 +148,39 @@ class ElementsWorker(BaseWorker): ...@@ -148,3 +148,39 @@ class ElementsWorker(BaseWorker):
def process_element(self, element): def process_element(self, element):
"""Override this method to analyze an Arkindex element from the provided list""" """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