From 52fb646535534b3fe4681d1cdd2fdd8a5f7a037c Mon Sep 17 00:00:00 2001 From: Chatewgne Date: Tue, 15 Oct 2024 11:10:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[BUG]=20Fix=20errors=20in=20Aggr?= =?UTF-8?q?egator=20when=20retrieving=20unpublished=20Route=20Steps=20(ref?= =?UTF-8?q?s=20#3569)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geotrek/trekking/parsers.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/geotrek/trekking/parsers.py b/geotrek/trekking/parsers.py index 5a863e197e..8039b69847 100644 --- a/geotrek/trekking/parsers.py +++ b/geotrek/trekking/parsers.py @@ -198,10 +198,12 @@ def filter_points_reference(self, src, val): def end(self): """Add children after all treks imported are created in database.""" self.next_url = f"{self.url}/api/v2/tour" + portals = self.portals_filter try: params = { 'in_bbox': ','.join([str(coord) for coord in self.bbox.extent]), - 'fields': 'steps,id' + 'portals': ','.join(portals) if portals else '', + 'fields': 'steps,id,uuid', } response = self.request_or_retry(f"{self.next_url}", params=params) results = response.json()['results'] @@ -219,6 +221,19 @@ def end(self): for child_id in value: response = self.request_or_retry(f"{self.url}/api/v2/trek/{child_id}") child_trek = response.json() + + # If the Tour step is linked to a Structure that is not published, + # we have to set it to its parent's Structure. + # Get structure mapping : + structure_mapping = self.field_options.get('structure', {}).get('mapping', {}) + # Check if structure appears in mapping : + if child_trek.get("structure") not in structure_mapping.keys(): + # Override JSON response with the parent's structure ID that exists in the mapping : + parent_structure_name = trek_parent_instance[0].structure.name + parent_structure_index = list(structure_mapping.values()).index(parent_structure_name) + parent_structure_remote_id = list(structure_mapping.keys())[parent_structure_index] + child_trek["structure"] = parent_structure_remote_id + self.parse_row(child_trek) trek_child_instance = self.obj OrderedTrekChild.objects.update_or_create(parent=trek_parent_instance[0],