Skip to content

moved expandable_fields to meta class #6198

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

Merged
merged 3 commits into from
Oct 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 22 additions & 30 deletions readthedocs/api/v3/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ class BuildSerializer(FlexFieldsModelSerializer):
state = BuildStateSerializer(source='*')
_links = BuildLinksSerializer(source='*')

expandable_fields = dict(
config=(
BuildConfigSerializer,
dict(
source='config',
),
),
)

class Meta:
model = Build
fields = [
Expand All @@ -140,6 +131,10 @@ class Meta:
'_links',
]

expandable_fields = {
'config': (BuildConfigSerializer, {'source': 'config'})
}

def get_finished(self, obj):
if obj.date and obj.length:
return obj.date + datetime.timedelta(seconds=obj.length)
Expand Down Expand Up @@ -215,15 +210,6 @@ class VersionSerializer(FlexFieldsModelSerializer):
urls = VersionURLsSerializer(source='*')
_links = VersionLinksSerializer(source='*')

expandable_fields = dict(
last_build=(
BuildSerializer,
dict(
source='last_build',
),
),
)

class Meta:
model = Version
fields = [
Expand All @@ -241,6 +227,12 @@ class Meta:
'_links',
]

expandable_fields = {
'last_build': (
BuildSerializer, {'source': 'last_build'}
)
}

def get_downloads(self, obj):
downloads = obj.get_downloads()
data = {}
Expand Down Expand Up @@ -448,18 +440,6 @@ class ProjectSerializer(FlexFieldsModelSerializer):
created = serializers.DateTimeField(source='pub_date')
modified = serializers.DateTimeField(source='modified_date')

expandable_fields = dict(
active_versions=(
VersionSerializer,
dict(
# NOTE: this has to be a Model method, can't be a
# ``SerializerMethodField`` as far as I know
source='active_versions',
many=True,
),
),
)

class Meta:
model = Project
fields = [
Expand Down Expand Up @@ -489,6 +469,18 @@ class Meta:
'_links',
]

expandable_fields = {
'active_versions': (
VersionSerializer,
{
# NOTE: this has to be a Model method, can't be a
# ``SerializerMethodField`` as far as I know
'source': 'active_versions',
'many': True,
}
)
}

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