Skip to content

Commit

Permalink
Added key default version in serializer Repository
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Jul 6, 2021
1 parent f632e5a commit 8ab5e89
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bothub/api/v2/repository/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ class Meta:
"use_name_entities",
"use_analyze_char",
"organization",
"version_default",
]
read_only = ["uuid", "created_at"]
ref_name = None
Expand Down Expand Up @@ -986,6 +987,7 @@ class Meta:
style={"show": False},
)
categories_list = serializers.SerializerMethodField(style={"show": False})
version_default = serializers.SerializerMethodField(style={"show": False})

def create(self, validated_data):
organization = validated_data.pop("organization", None)
Expand Down Expand Up @@ -1017,6 +1019,13 @@ def get_intents(self, obj):
def get_categories_list(self, obj):
return RepositoryCategorySerializer(obj.categories, many=True).data

def get_version_default(self, obj):
return {
"id": obj.current_version().repository_version.pk,
"repository_version_language_id": obj.current_version().pk,
"name": obj.current_version().repository_version.name,
}


class RepositoryPermissionSerializer(serializers.ModelSerializer):
class Meta:
Expand Down Expand Up @@ -1109,6 +1118,7 @@ class Meta:
"owner__nickname",
"absolute_url",
"votes",
"version_default",
]
read_only = fields
ref_name = None
Expand All @@ -1123,13 +1133,21 @@ class Meta:
absolute_url = serializers.SerializerMethodField()
intents = serializers.SerializerMethodField(style={"show": False})
votes = RepositoryVotesSerializer(many=True, read_only=True)
version_default = serializers.SerializerMethodField(style={"show": False})

def get_intents(self, obj):
return obj.get_formatted_intents()

def get_absolute_url(self, obj):
return obj.get_absolute_url()

def get_version_default(self, obj):
return {
"id": obj.current_version().repository_version.pk,
"repository_version_language_id": obj.current_version().pk,
"name": obj.current_version().repository_version.name,
}


class RepositoryContributionsSerializer(serializers.ModelSerializer):
class Meta:
Expand Down

0 comments on commit 8ab5e89

Please sign in to comment.