Skip to content

Commit

Permalink
💫 [IMPR] Add missing translations for fields on Courses and Sites in …
Browse files Browse the repository at this point in the history
…APIv2 (refs #3569)
  • Loading branch information
Chatewgne committed Jan 24, 2024
1 parent dcc3f0d commit a0ab4d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------
Expand Down
36 changes: 36 additions & 0 deletions geotrek/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]

Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down

0 comments on commit a0ab4d8

Please sign in to comment.