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 10, 2024
1 parent 34e82c4 commit cb56301
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 58 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
5 changes: 3 additions & 2 deletions geotrek/common/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ def test_geotrek_aggregator_parser(self, mocked_head, mocked_get):
('trekking', 'trek_ids.json'),
('trekking', 'trek.json'),
('trekking', 'trek_children.json'),
('trekking', 'trek_unpublished_step.json'),
('trekking', 'poi_ids.json'),
('trekking', 'poi.json'),
('tourism', 'informationdesk_ids.json'),
Expand Down Expand Up @@ -885,9 +886,9 @@ def test_geotrek_aggregator_parser(self, mocked_head, mocked_get):
string_parser = output.getvalue()
self.assertIn('0000: Trek (URL_1) (00%)', string_parser)
self.assertIn('0000: Poi (URL_1) (00%)', string_parser)
self.assertIn('5/5 lignes importƩes.', string_parser)
self.assertIn('6/6 lignes importƩes.', string_parser)
self.assertIn('2/2 lignes importƩes.', string_parser)
self.assertEqual(Trek.objects.count(), 5)
self.assertEqual(Trek.objects.count(), 6)
self.assertEqual(POI.objects.count(), 2)
self.assertEqual(1, Trek.objects.get(name="Foo").information_desks.count())
self.assertEqual("Office de Tourisme de Seix",
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 cb56301

Please sign in to comment.