Skip to content

Commit

Permalink
šŸ› [BUG] Fix Aggregator does not retrieve unpublished Tour Steps (refs #ā€¦
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Sep 9, 2024
1 parent 34e82c4 commit 23cbd00
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 56 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CHANGELOG
- ApidaeTrekParser duration import is fixed for multiple-days treks
- Apidae tourism parser now handles missing contact properties
- ApidaeTrekParser now handles missing source website
- Fix Aggregator does not retrieve unpublished Tour Steps (#3569)"

**Documentation**

Expand Down
17 changes: 10 additions & 7 deletions geotrek/trekking/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ def filter_points_reference(self, src, val):

def end(self):
"""Add children after all treks imported are created in database."""
super().end()

self.next_url = f"{self.url}/api/v2/tour"
try:
params = {
'in_bbox': ','.join([str(coord) for coord in self.bbox.extent]),
'fields': 'steps,uuid'
'fields': 'steps,uuid,id'
}
response = self.request_or_retry(f"{self.next_url}", params=params)
results = response.json()['results']
final_children = {}
for result in results:
final_children[result['uuid']] = [step['uuid'] for step in result['steps']]
final_children[result['uuid']] = [(step['id'], step['uuid']) for step in result['steps']]

for key, value in final_children.items():
if value:
Expand All @@ -217,18 +217,21 @@ def end(self):
self.add_warning(_(f"Trying to retrieve children for missing trek : could not find trek with UUID {key}"))
return
order = 0
for child in value:
for child_id, child_uid in value:
try:
trek_child_instance = Trek.objects.get(eid=child)
trek_child_instance = Trek.objects.get(eid=child_uid)
except Trek.DoesNotExist:
self.add_warning(_(f"One trek has not be generated for {trek_parent_instance[0].name} : could not find trek with UUID {child}"))
continue
response = self.request_or_retry(f"{self.url}/api/v2/trek/{child_id}")
child_trek = response.json()
self.parse_row(child_trek)
trek_child_instance = self.obj
OrderedTrekChild.objects.update_or_create(parent=trek_parent_instance[0],
child=trek_child_instance,
defaults={'order': order})
order += 1
except Exception as e:
self.add_warning(_(f"An error occured in children generation : {getattr(e, 'message', repr(e))}"))
super().end()


class GeotrekServiceParser(GeotrekParser):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"uuid": "9e70b294-1134-4c50-9c56-d722720cacf1",
"steps": [
{
"id": 10439,
"uuid": "c9567576-2934-43ab-979e-e13d02c671a9"
},
{
"id": 10442,
"uuid": "9e70b294-1134-4c50-9c56-d722720cace6"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"uuid": "9e70b294-1134-4c50-9c56-d722720cacf1",
"steps": [
{
"uuid": "c9567576-2934-43ab-979e-e13d02c671a9"
"uuid": "c9567576-2934-43ab-979e-e13d02c671a9",
"id": 1234
},
{
"uuid": "c9567576-2934-43ab-666e-e13d02c671a9"
"uuid": "c9567576-2934-43ab-666e-e13d02c671a9",
"id": 1235
}
]
},
Expand All @@ -34,7 +36,8 @@
"uuid": "b2aea666-5e6e-4daa-a750-7d2ee52d3fe1",
"steps": [
{
"uuid": "c9567576-2934-43ab-979e-e13d02c671a9"
"uuid": "c9567576-2934-43ab-979e-e13d02c671a9",
"id": 457
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"detail": "No Trek matches the given query."
}
Loading

0 comments on commit 23cbd00

Please sign in to comment.