From a0ab4d83d01673b6c2cc8ed774a6478e361188a1 Mon Sep 17 00:00:00 2001 From: Chatewgne Date: Wed, 24 Jan 2024 13:07:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20[IMPR]=20Add=20missing=20transla?= =?UTF-8?q?tions=20for=20fields=20on=20Courses=20and=20Sites=20in=20APIv2?= =?UTF-8?q?=20(refs=20#3569)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/changelog.rst | 4 ++++ geotrek/api/v2/serializers.py | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index d2227b73c4..df7127dca6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,6 +9,10 @@ CHANGELOG - Add UUIDs of parent and children ``Courses`` and ``Sites`` in APIv2 (#3569) +**Improvements** + +- Add missing translations for fields on ``Courses`` and ``Sites`` in APIv2 (#3569) + 2.101.5 (2024-01-11) -------------------- diff --git a/geotrek/api/v2/serializers.py b/geotrek/api/v2/serializers.py index 694c7c5df3..7c6344953d 100644 --- a/geotrek/api/v2/serializers.py +++ b/geotrek/api/v2/serializers.py @@ -1140,6 +1140,12 @@ class Meta: fields = ('id', 'name') class SiteSerializer(PDFSerializerMixin, DynamicFieldsMixin, PublishedRelatedObjectsSerializerMixin, serializers.ModelSerializer): + name = serializers.SerializerMethodField() + accessibility = serializers.SerializerMethodField() + advice = serializers.SerializerMethodField() + description = serializers.SerializerMethodField() + description_teaser = serializers.SerializerMethodField() + period = serializers.SerializerMethodField() url = HyperlinkedIdentityField(view_name='apiv2:site-detail') geometry = geo_serializers.GeometryField(read_only=True, source="geom_transformed", precision=7) attachments = AttachmentSerializer(many=True) @@ -1157,6 +1163,24 @@ class SiteSerializer(PDFSerializerMixin, DynamicFieldsMixin, PublishedRelatedObj web_links = WebLinkSerializer(many=True) view_points = HDViewPointSerializer(many=True) + def get_name(self, obj): + return get_translation_or_dict('name', self, obj) + + def get_accessibility(self, obj): + return get_translation_or_dict('accessibility', self, obj) + + def get_advice(self, obj): + return get_translation_or_dict('advice', self, obj) + + def get_description(self, obj): + return get_translation_or_dict('description', self, obj) + + def get_description_teaser(self, obj): + return get_translation_or_dict('description_teaser', self, obj) + + def get_period(self, obj): + return get_translation_or_dict('period', self, obj) + def get_cities(self, obj): return [city.code for city in obj.published_cities] @@ -1200,6 +1224,9 @@ class Meta: ) class CourseSerializer(PDFSerializerMixin, DynamicFieldsMixin, PublishedRelatedObjectsSerializerMixin, serializers.ModelSerializer): + name = serializers.SerializerMethodField() + advice = serializers.SerializerMethodField() + description = serializers.SerializerMethodField() url = HyperlinkedIdentityField(view_name='apiv2:course-detail') geometry = geo_serializers.GeometryField(read_only=True, source="geom_transformed", precision=7) children = serializers.SerializerMethodField() @@ -1218,6 +1245,15 @@ class CourseSerializer(PDFSerializerMixin, DynamicFieldsMixin, PublishedRelatedO cities = serializers.SerializerMethodField() districts = serializers.SerializerMethodField() + def get_name(self, obj): + return get_translation_or_dict('name', self, obj) + + def get_advice(self, obj): + return get_translation_or_dict('advice', self, obj) + + def get_description(self, obj): + return get_translation_or_dict('description', self, obj) + def get_accessibility(self, obj): return get_translation_or_dict('accessibility', self, obj)