From 044b35eb42ae5a5fefa0e45c406c0f86e870743d Mon Sep 17 00:00:00 2001 From: Eva Bardou <ebardou@teklia.com> Date: Thu, 23 Jul 2020 11:27:11 +0200 Subject: [PATCH 1/2] Add generic function create_sub_element() --- arkindex_worker/worker.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arkindex_worker/worker.py b/arkindex_worker/worker.py index a0750937..c8cdeb12 100644 --- a/arkindex_worker/worker.py +++ b/arkindex_worker/worker.py @@ -148,3 +148,16 @@ 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): + self.api_client.request( + "CreateElement", + body={ + "type": type, + "name": name, + "image": element.zone.image.id, + "corpus": element.corpus.id, + "polygon": polygon, + "parent": element.id, + }, + ) -- GitLab From 2e42f56fa2a8d1b403a69a824f0923374cc8bf29 Mon Sep 17 00:00:00 2001 From: Eva Bardou <ebardou@teklia.com> Date: Thu, 23 Jul 2020 14:49:00 +0200 Subject: [PATCH 2/2] Fix some review related code snippets --- arkindex_worker/worker.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arkindex_worker/worker.py b/arkindex_worker/worker.py index c8cdeb12..99971d3b 100644 --- a/arkindex_worker/worker.py +++ b/arkindex_worker/worker.py @@ -150,6 +150,29 @@ class ElementsWorker(BaseWorker): """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={ -- GitLab