forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [FC-0031] Use serializer instead of custom function
- Loading branch information
1 parent
3bb8ebc
commit 462c780
Showing
3 changed files
with
67 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Course Info serializers | ||
""" | ||
from rest_framework import serializers | ||
|
||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview | ||
|
||
|
||
class CourseInfoOverviewSerializer(serializers.ModelSerializer): | ||
""" | ||
Serializer for serialize additional fields in BlocksInfoInCourseView. | ||
""" | ||
|
||
name = serializers.CharField(source='display_name') | ||
number = serializers.CharField(source='display_number_with_default') | ||
org = serializers.CharField(source='display_org_with_default') | ||
is_self_paced = serializers.BooleanField(source='self_paced') | ||
media = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = CourseOverview | ||
fields = ( | ||
'name', | ||
'number', | ||
'org', | ||
'start', | ||
'start_display', | ||
'start_type', | ||
'end', | ||
'is_self_paced', | ||
'media', | ||
) | ||
|
||
@staticmethod | ||
def get_media(obj): | ||
return {'image': obj.image_urls} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters