From 2b4968c6aef1a71604c1089e79ba2e5bb5eb4fd1 Mon Sep 17 00:00:00 2001 From: Chatewgne Date: Wed, 18 Sep 2024 11:39:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[BUG]=20Fix=20missing=20Annotati?= =?UTF-8?q?on=20Categories=20in=20APIv2=20for=20annotations=20other=20than?= =?UTF-8?q?=20Points=20(refs=20#4032)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/changelog.rst | 1 + geotrek/api/tests/test_v2.py | 48 ++++++++++++++++++++++++++++++++++- geotrek/api/v2/serializers.py | 3 +-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index af65d32466..5cce1c2b4b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -24,6 +24,7 @@ CHANGELOG - Apidae tourism parser now handles missing contact properties - ApidaeTrekParser now handles missing source website - Fix Aggregator does not retrieve unpublished Tour Steps (#3569)" +- Fix missing Annotation Categories in APIv2 for annotations other than Points (#4032)" **Documentation** diff --git a/geotrek/api/tests/test_v2.py b/geotrek/api/tests/test_v2.py index c7829b78f1..41ac39cbfb 100644 --- a/geotrek/api/tests/test_v2.py +++ b/geotrek/api/tests/test_v2.py @@ -515,10 +515,34 @@ def setUpTestData(cls): "annotationId": 2, "annotationType": "point", } + }, + { + "type": "Feature", + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 296.59070688800216, + 107.85521976008415 + ], + [ + 295.2543114908704, + 27.671495932178686 + ] + ] + }, + "properties": { + "name": "Line 6", + "annotationId": 12345, + "annotationType": "line", + } } ] } - annotations_categories = {'1234': str(cls.annotationcategory.pk)} + annotations_categories = { + '1234': str(cls.annotationcategory.pk), + '12345': str(cls.annotationcategory.pk) + } cls.hdviewpoint_trek = common_factory.HDViewPointFactory( content_object=cls.treks[0], annotations=annotations, @@ -2561,6 +2585,28 @@ def test_hdviewpoint_detail_content(self): "annotationType": "point", "category": None } + }, + { + "type": "Feature", + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 296.59070688800216, + 107.85521976008415 + ], + [ + 295.2543114908704, + 27.671495932178686 + ] + ] + }, + "properties": { + "name": "Line 6", + "annotationId": 12345, + "annotationType": "line", + "category": self.annotationcategory.pk + } } ] } diff --git a/geotrek/api/v2/serializers.py b/geotrek/api/v2/serializers.py index d831bf01f4..435cc81b1b 100644 --- a/geotrek/api/v2/serializers.py +++ b/geotrek/api/v2/serializers.py @@ -405,8 +405,7 @@ def get_annotations(self, obj): annotations_categories = obj.annotations_categories for feature in annotations.get("features", []): feat_id = feature["properties"]["annotationId"] - feat_type = feature["geometry"]["type"] - if feat_type == "Point" and str(feat_id) in annotations_categories.keys(): + if str(feat_id) in annotations_categories.keys(): feature["properties"]['category'] = int(annotations_categories[str(feat_id)]) else: feature["properties"]['category'] = None