Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIv3 refactor some fields #5868

Merged
merged 7 commits into from Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 23 additions & 11 deletions readthedocs/api/v3/serializers.py
Expand Up @@ -301,13 +301,26 @@ def get_name(self, programming_language):
return 'Unknown'


class ProjectURLsSerializer(serializers.Serializer):
class ProjectURLsSerializer(BaseLinksSerializer, serializers.Serializer):

"""Serializer with all the user-facing URLs under Read the Docs."""

documentation = serializers.CharField(source='get_docs_url')
project_homepage = serializers.SerializerMethodField()
home = serializers.SerializerMethodField()
builds = serializers.SerializerMethodField()
versions = serializers.SerializerMethodField()

def get_project_homepage(self, obj):
# Overridden only to return ``None`` when the description is ``''``
return obj.project_url or None
def get_home(self, obj):
path = reverse('projects_detail', kwargs={'project_slug': obj.slug})
return self._absolute_url(path)

def get_builds(self, obj):
path = reverse('builds_project_list', kwargs={'project_slug': obj.slug})
return self._absolute_url(path)

def get_versions(self, obj):
path = reverse('project_version_list', kwargs={'project_slug': obj.slug})
return self._absolute_url(path)


class RepositorySerializer(serializers.Serializer):
Expand Down Expand Up @@ -388,6 +401,7 @@ def get_translations(self, obj):

class ProjectSerializer(FlexFieldsModelSerializer):

homepage = serializers.SerializerMethodField()
language = LanguageSerializer()
programming_language = ProgrammingLanguageSerializer()
repository = RepositorySerializer(source='*')
Expand All @@ -399,8 +413,6 @@ class ProjectSerializer(FlexFieldsModelSerializer):
tags = serializers.StringRelatedField(many=True)
users = UserSerializer(many=True)

description = serializers.SerializerMethodField()

_links = ProjectLinksSerializer(source='*')

# TODO: adapt these fields with the proper names in the db and then remove
Expand All @@ -426,11 +438,11 @@ class Meta:
'id',
'name',
'slug',
'description',
'created',
'modified',
'language',
'programming_language',
'homepage',
'repository',
'default_version',
'default_branch',
Expand All @@ -449,9 +461,9 @@ class Meta:
'_links',
]

def get_description(self, obj):
# Overridden only to return ``None`` when the description is ``''``
return obj.description or None
def get_homepage(self, obj):
# Overridden only to return ``None`` when the project_url is ``''``
return obj.project_url or None

def get_translation_of(self, obj):
if obj.main_language_project:
Expand Down
6 changes: 4 additions & 2 deletions readthedocs/api/v3/tests/responses/projects-detail.json
Expand Up @@ -51,7 +51,6 @@
"created": "2019-04-29T10:00:00Z",
"default_branch": "master",
"default_version": "latest",
"description": "Project description",
"id": 1,
"language": {
"code": "en",
Expand All @@ -76,6 +75,7 @@
"code": "words",
"name": "Only Words"
},
"homepage": "http://project.com",
"repository": {
"type": "git",
"url": "https://github.com/rtfd/project"
Expand All @@ -89,8 +89,10 @@
],
"translation_of": null,
"urls": {
"builds": "https://readthedocs.org/projects/project/builds/",
"documentation": "http://readthedocs.org/docs/project/en/latest/",
"project_homepage": "http://project.com"
"home": "https://readthedocs.org/projects/project/",
"versions": "https://readthedocs.org/projects/project/versions/"
},
"users": [
{
Expand Down
6 changes: 4 additions & 2 deletions readthedocs/api/v3/tests/responses/projects-list.json
Expand Up @@ -7,7 +7,6 @@
"id": 1,
"name": "project",
"slug": "project",
"description": "Project description",
"created": "2019-04-29T10:00:00Z",
"modified": "2019-04-29T12:00:00Z",
"language": {
Expand All @@ -18,6 +17,7 @@
"code": "words",
"name": "Only Words"
},
"homepage": "http://project.com",
"repository": {
"url": "https://github.com/rtfd/project",
"type": "git"
Expand All @@ -31,8 +31,10 @@
"subproject_of": null,
"translation_of": null,
"urls": {
"builds": "https://readthedocs.org/projects/project/builds/",
"documentation": "http://readthedocs.org/docs/project/en/latest/",
"project_homepage": "http://project.com"
"home": "https://readthedocs.org/projects/project/",
"versions": "https://readthedocs.org/projects/project/versions/"
},
"tags": [
"tag",
Expand Down
Expand Up @@ -7,7 +7,6 @@
"id": 2,
"name": "subproject",
"slug": "subproject",
"description": "SubProject description",
"created": "2019-04-29T10:00:00Z",
"modified": "2019-04-29T12:00:00Z",
"language": {
Expand All @@ -18,6 +17,7 @@
"code": "words",
"name": "Only Words"
},
"homepage": "http://subproject.com",
"repository": {
"url": "https://github.com/rtfd/subproject",
"type": "git"
Expand All @@ -32,7 +32,6 @@
"id": 1,
"name": "project",
"slug": "project",
"description": "Project description",
"created": "2019-04-29T10:00:00Z",
"modified": "2019-04-29T12:00:00Z",
"language": {
Expand All @@ -43,6 +42,7 @@
"code": "words",
"name": "Only Words"
},
"homepage": "http://project.com",
"repository": {
"url": "https://github.com/rtfd/project",
"type": "git"
Expand All @@ -56,8 +56,10 @@
"subproject_of": null,
"translation_of": null,
"urls": {
"builds": "https://readthedocs.org/projects/project/builds/",
"documentation": "http://readthedocs.org/docs/project/en/latest/",
"project_homepage": "http://project.com"
"home": "https://readthedocs.org/projects/project/",
"versions": "https://readthedocs.org/projects/project/versions/"
},
"tags": [
"tag",
Expand All @@ -82,8 +84,10 @@
},
"translation_of": null,
"urls": {
"builds": "https://readthedocs.org/projects/subproject/builds/",
"documentation": "http://readthedocs.org/docs/project/projects/subproject/en/latest/",
"project_homepage": "http://subproject.com"
"home": "https://readthedocs.org/projects/subproject/",
"versions": "https://readthedocs.org/projects/subproject/versions/"
},
"tags": [],
"users": [],
Expand Down
6 changes: 4 additions & 2 deletions readthedocs/api/v3/tests/responses/projects-superproject.json
Expand Up @@ -2,7 +2,6 @@
"created": "2019-04-29T10:00:00Z",
"default_branch": "master",
"default_version": "latest",
"description": "Project description",
"id": 1,
"language": {
"code": "en",
Expand All @@ -27,6 +26,7 @@
"code": "words",
"name": "Only Words"
},
"homepage": "http://project.com",
"repository": {
"type": "git",
"url": "https://github.com/rtfd/project"
Expand All @@ -40,8 +40,10 @@
],
"translation_of": null,
"urls": {
"builds": "https://readthedocs.org/projects/project/builds/",
"documentation": "http://readthedocs.org/docs/project/en/latest/",
"project_homepage": "http://project.com"
"home": "https://readthedocs.org/projects/project/",
"versions": "https://readthedocs.org/projects/project/versions/"
},
"users": [
{
Expand Down
Expand Up @@ -23,7 +23,6 @@
"created": "2019-04-29T10:00:00Z",
"default_branch": "master",
"default_version": "latest",
"description": "Project description",
"id": 1,
"language": {
"code": "en",
Expand All @@ -48,6 +47,7 @@
"code": "words",
"name": "Only Words"
},
"homepage": "http://project.com",
"repository": {
"type": "git",
"url": "https://github.com/rtfd/project"
Expand All @@ -61,8 +61,10 @@
],
"translation_of": null,
"urls": {
"builds": "https://readthedocs.org/projects/project/builds/",
"documentation": "http://readthedocs.org/docs/project/en/latest/",
"project_homepage": "http://project.com"
"home": "https://readthedocs.org/projects/project/",
"versions": "https://readthedocs.org/projects/project/versions/"
},
"users": [
{
Expand Down