Skip to content

Commit

Permalink
šŸ› [BUG] Fix errors in Aggregator when retrieving unpublished Route Stā€¦
Browse files Browse the repository at this point in the history
ā€¦eps (refs #3569)
  • Loading branch information
Chatewgne committed Oct 15, 2024
1 parent 840ea53 commit 52fb646
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion geotrek/trekking/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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],
Expand Down

0 comments on commit 52fb646

Please sign in to comment.