Commit eab05dcd authored by Michal Čihař's avatar Michal Čihař

Remove duplicated self links while listing components or translations

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 65faa05d
......@@ -48,6 +48,17 @@ class MultiFieldHyperlinkedIdentityField(serializers.HyperlinkedIdentityField):
)
class RemovableSerializer(serializers.ModelSerializer):
def __init__(self, *args, **kwargs):
remove_fields = kwargs.pop('remove_fields', None)
super(RemovableSerializer, self).__init__(*args, **kwargs)
if remove_fields:
# for multiple fields in a list
for field_name in remove_fields:
self.fields.pop(field_name)
class LanguageSerializer(serializers.ModelSerializer):
web_url = serializers.CharField(source='get_absolute_url', read_only=True)
......@@ -82,7 +93,7 @@ class ProjectSerializer(serializers.ModelSerializer):
}
class ComponentSerializer(serializers.ModelSerializer):
class ComponentSerializer(RemovableSerializer):
web_url = serializers.CharField(source='get_absolute_url', read_only=True)
project = ProjectSerializer(read_only=True)
......@@ -103,7 +114,7 @@ class ComponentSerializer(serializers.ModelSerializer):
}
class TranslationSerializer(serializers.ModelSerializer):
class TranslationSerializer(RemovableSerializer):
web_url = serializers.CharField(
source='get_absolute_url', read_only=True
)
......
......@@ -148,7 +148,8 @@ class ProjectViewSet(WeblateViewSet):
serializer = ComponentSerializer(
page,
many=True,
context={'request': request}
context={'request': request},
remove_fields=('project',),
)
return self.get_paginated_response(serializer.data)
......@@ -239,7 +240,8 @@ class ComponentViewSet(MultipleFieldMixin, WeblateViewSet):
serializer = TranslationSerializer(
page,
many=True,
context={'request': request}
context={'request': request},
remove_fields=('component',),
)
return self.get_paginated_response(serializer.data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment