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 a84b749
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 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
4 changes: 2 additions & 2 deletions geotrek/api/tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
'accessibility', 'advice', 'ambiance', 'attachments', 'children', 'children_uuids', 'cities', 'courses', 'courses_uuids', 'description',
'description_teaser', 'districts', 'eid', 'geometry', 'id', 'information_desks', 'labels', 'managers', 'name', 'orientation', 'parent',
'parent_uuid', 'period', 'portal', 'practice', 'provider', 'pdf', 'ratings', 'sector', 'source', 'structure', 'themes', 'type', 'url', 'uuid',
'view_points', 'wind', 'web_links'
'view_points', 'published', 'wind', 'web_links'
])

OUTDOORPRACTICE_PROPERTIES_JSON_STRUCTURE = sorted(['id', 'name', 'sector', 'pictogram'])
Expand All @@ -188,7 +188,7 @@
'accessibility', 'advice', 'cities', 'description', 'districts', 'eid', 'equipment', 'geometry', 'height', 'id',
'length', 'name', 'ratings', 'ratings_description', 'sites', 'sites_uuids', 'structure',
'type', 'url', 'attachments', 'max_elevation', 'min_elevation', 'parents', 'parents_uuids', 'provider',
'pdf', 'points_reference', 'children', 'children_uuids', 'duration', 'gear', 'uuid'
'pdf', 'points_reference', 'published', 'children', 'children_uuids', 'duration', 'gear', 'uuid'
])

COURSETYPE_PROPERTIES_JSON_STRUCTURE = sorted(['id', 'name', 'practice'])
Expand Down
50 changes: 47 additions & 3 deletions geotrek/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,13 @@ 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()
published = 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 +1164,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 All @@ -1166,6 +1191,9 @@ def get_districts(self, obj):
def get_labels(self, obj):
return [label.pk for label in obj.published_labels]

def get_published(self, obj):
return get_translation_or_dict('published', self, obj)

def get_courses(self, obj):
return self.get_values_on_published_related_objects(obj.children_courses.all(), 'pk')

Expand Down Expand Up @@ -1195,16 +1223,20 @@ class Meta:
'id', 'accessibility', 'advice', 'ambiance', 'attachments', 'cities', 'children', 'children_uuids', 'description',
'description_teaser', 'districts', 'eid', 'geometry', 'information_desks', 'labels', 'managers',
'name', 'orientation', 'pdf', 'period', 'parent', 'parent_uuid', 'portal', 'practice', 'provider',
'ratings', 'sector', 'source', 'structure', 'themes', 'view_points',
'ratings', 'sector', 'source', 'structure', 'themes', 'view_points', 'published'
'type', 'url', 'uuid', 'courses', 'courses_uuids', 'web_links', 'wind',
)

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()
parents = serializers.SerializerMethodField()
parents_uuids = serializers.SerializerMethodField()
published = serializers.SerializerMethodField()
children_uuids = serializers.SerializerMethodField()
accessibility = serializers.SerializerMethodField()
attachments = AttachmentSerializer(many=True, source='sorted_attachments')
Expand All @@ -1218,6 +1250,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 All @@ -1230,6 +1271,9 @@ def get_districts(self, obj):
def get_equipment(self, obj):
return get_translation_or_dict('equipment', self, obj)

def get_published(self, obj):
return get_translation_or_dict('published', self, obj)

def get_gear(self, obj):
return get_translation_or_dict('gear', self, obj)

Expand Down Expand Up @@ -1282,8 +1326,8 @@ class Meta:
model = outdoor_models.Course
fields = (
'id', 'accessibility', 'advice', 'attachments', 'children', 'children_uuids', 'cities', 'description', 'districts', 'duration', 'eid',
'equipment', 'gear', 'geometry', 'height', 'length', 'max_elevation',
'min_elevation', 'name', 'parents', 'parents_uuids', 'pdf', 'points_reference', 'provider', 'ratings', 'ratings_description',
'equipment', 'gear', 'geometry', 'height', 'length', 'max_elevation', 'min_elevation', 'name', 'parents',
'parents_uuids', 'pdf', 'points_reference', 'published', 'provider', 'ratings', 'ratings_description',
'sites', 'sites_uuids', 'structure', 'type', 'url', 'uuid'
)

Expand Down

0 comments on commit a84b749

Please sign in to comment.