diff --git a/setuper/pyramid.py b/setuper/pyramid.py index e7a1814416..31497724e6 100644 --- a/setuper/pyramid.py +++ b/setuper/pyramid.py @@ -15,6 +15,7 @@ def setup_orgunits(account_name, iaso_client): test_file = "data/small_sample.gpkg" geopackage_file = {"file": (test_file, open(test_file, "rb"), "application/octet-stream")} task = iaso_client.post("/api/tasks/create/importgpkg/", files=geopackage_file, data=data) + print("-- Importing org units") iaso_client.wait_task_completion(task) @@ -26,5 +27,27 @@ def setup_orgunits(account_name, iaso_client): "searches": [{"validation_status": "all", "color": "f4511e", "source": data_source_id}], } task = iaso_client.post("/api/tasks/create/orgunitsbulkupdate/", json=data) - + update_org_unit_sub_type(iaso_client, project_id) iaso_client.wait_task_completion(task) + + +def update_org_unit_sub_type(iaso_client, project_id): + print("-- Updating org unit sub type") + org_unit_types = iaso_client.get("/api/v2/orgunittypes/")["orgUnitTypes"] + for org_unit_type in org_unit_types: + org_unit_type_level = org_unit_type["depth"] + org_unit_type_id = org_unit_type["id"] + sub_unit_type_ids = [ + org_unit_type["id"] + for org_unit_type in org_unit_types + if org_unit_type["depth"] == (org_unit_type_level + 1) + ] + if len(sub_unit_type_ids) > 0: + current_type = { + "name": org_unit_type["name"], + "short_name": org_unit_type["short_name"], + "project_ids": [project_id], + "sub_unit_type_ids": sub_unit_type_ids, + } + # Updating default sub type + iaso_client.patch(f"/api/v2/orgunittypes/{org_unit_type_id}/", json=current_type)