From e38f86e8b009647ef52821bab0bebb28bc02200e Mon Sep 17 00:00:00 2001 From: Szabo Zoltan Date: Thu, 16 Jan 2025 19:18:37 +0100 Subject: [PATCH] Molnix data structure change --- api/management/commands/sync_molnix.py | 4 ++++ api/molnix_utils.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/api/management/commands/sync_molnix.py b/api/management/commands/sync_molnix.py index 9b6a57873..1b990f3f2 100644 --- a/api/management/commands/sync_molnix.py +++ b/api/management/commands/sync_molnix.py @@ -293,6 +293,9 @@ def sync_deployments(molnix_deployments, molnix_api, countries): # Create Personnel objects for md in molnix_deployments: + if "position_id" not in md: # changed structure § + md2 = molnix_api.get_deployment(md["id"]) + md |= md2["deployment"] if skip_this(md["tags"]): warning = "Deployment id %d skipped due to No-GO" % md["id"] logger.warning(warning) @@ -322,6 +325,7 @@ def sync_deployments(molnix_deployments, molnix_api, countries): surge_alert = None try: + # Should not happen after the "changed structure §" fix: if "position_id" not in md: warning = "%d deployment did not find SurgeAlert in lack of Molnix position_id" % md["id"] logger.warning(warning) diff --git a/api/molnix_utils.py b/api/molnix_utils.py index 037cd97ca..bdb320743 100644 --- a/api/molnix_utils.py +++ b/api/molnix_utils.py @@ -89,6 +89,12 @@ def get_position(self, id): except Exception: return None + def get_deployment(self, id): + try: + return self.call_api(path="deployments/%d" % id) + except Exception: + return None + def get_countries(self): countries = self.call_api(path="countries") countries_list = countries["countries"]