Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
39214f4d
Commit
39214f4d
authored
Apr 06, 2016
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #60 from edx/clintonb/nested-runs
Serializer updates
parents
c7d0af60
7c7e2f72
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
30 deletions
+33
-30
course_discovery/apps/api/serializers.py
+27
-26
course_discovery/apps/api/tests/test_serializers.py
+6
-4
No files found.
course_discovery/apps/api/serializers.py
View file @
39214f4d
...
...
@@ -2,7 +2,7 @@ from django.utils.translation import ugettext_lazy as _
from
rest_framework
import
serializers
from
course_discovery.apps.catalogs.models
import
Catalog
from
course_discovery.apps.course_metadata.models
import
(
from
course_discovery.apps.course_metadata.models
import
(
Course
,
CourseRun
,
Image
,
Organization
,
Person
,
Prerequisite
,
Seat
,
Subject
,
Video
)
...
...
@@ -15,7 +15,7 @@ class NamedModelSerializer(serializers.ModelSerializer):
name
=
serializers
.
CharField
()
class
Meta
(
object
):
fields
=
(
'name'
,
)
fields
=
(
'name'
,)
class
SubjectSerializer
(
NamedModelSerializer
):
...
...
@@ -47,7 +47,7 @@ class VideoSerializer(MediaSerializer):
class
Meta
(
object
):
model
=
Video
fields
=
(
'src'
,
'description'
,
'image'
,
)
fields
=
(
'src'
,
'description'
,
'image'
,)
class
SeatSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -65,7 +65,7 @@ class SeatSerializer(serializers.ModelSerializer):
class
Meta
(
object
):
model
=
Seat
fields
=
(
'type'
,
'price'
,
'currency'
,
'upgrade_deadline'
,
'credit_provider'
,
'credit_hours'
,
)
fields
=
(
'type'
,
'price'
,
'currency'
,
'upgrade_deadline'
,
'credit_provider'
,
'credit_hours'
,)
class
PersonSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -73,7 +73,7 @@ class PersonSerializer(serializers.ModelSerializer):
class
Meta
(
object
):
model
=
Person
fields
=
(
'name'
,
'title'
,
'bio'
,
'profile_image'
,)
fields
=
(
'
key'
,
'
name'
,
'title'
,
'bio'
,
'profile_image'
,)
class
OrganizationSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -81,7 +81,7 @@ class OrganizationSerializer(serializers.ModelSerializer):
class
Meta
(
object
):
model
=
Organization
fields
=
(
'
name'
,
'description'
,
'logo_image'
,
'homepage_url'
,
)
fields
=
(
'
key'
,
'name'
,
'description'
,
'logo_image'
,
'homepage_url'
,
)
class
CatalogSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -90,26 +90,8 @@ class CatalogSerializer(serializers.ModelSerializer):
fields
=
(
'id'
,
'name'
,
'query'
,
'courses_count'
,)
class
CourseSerializer
(
TimestampModelSerializer
):
level_type
=
serializers
.
SlugRelatedField
(
read_only
=
True
,
slug_field
=
'name'
)
subjects
=
SubjectSerializer
(
many
=
True
)
prerequisites
=
PrerequisiteSerializer
(
many
=
True
)
expected_learning_items
=
serializers
.
SlugRelatedField
(
many
=
True
,
read_only
=
True
,
slug_field
=
'value'
)
image
=
ImageSerializer
()
video
=
VideoSerializer
()
owners
=
OrganizationSerializer
(
many
=
True
)
sponsors
=
OrganizationSerializer
(
many
=
True
)
class
Meta
(
object
):
model
=
Course
fields
=
(
'key'
,
'title'
,
'short_description'
,
'full_description'
,
'level_type'
,
'subjects'
,
'prerequisites'
,
'expected_learning_items'
,
'image'
,
'video'
,
'owners'
,
'sponsors'
,
'modified'
,
)
class
CourseRunSerializer
(
TimestampModelSerializer
):
course
=
serializers
.
SlugRelatedField
(
read_only
=
True
,
slug_field
=
'key'
)
content_language
=
serializers
.
SlugRelatedField
(
read_only
=
True
,
slug_field
=
'code'
,
source
=
'language'
)
transcript_languages
=
serializers
.
SlugRelatedField
(
many
=
True
,
read_only
=
True
,
slug_field
=
'code'
)
image
=
ImageSerializer
()
...
...
@@ -121,13 +103,32 @@ class CourseRunSerializer(TimestampModelSerializer):
class
Meta
(
object
):
model
=
CourseRun
fields
=
(
'key'
,
'title'
,
'short_description'
,
'full_description'
,
'start'
,
'end'
,
'
course'
,
'
key'
,
'title'
,
'short_description'
,
'full_description'
,
'start'
,
'end'
,
'enrollment_start'
,
'enrollment_end'
,
'announcement'
,
'image'
,
'video'
,
'seats'
,
'content_language'
,
'transcript_languages'
,
'instructors'
,
'staff'
,
'pacing_type'
,
'min_effort'
,
'max_effort'
,
'modified'
,
)
class
CourseSerializer
(
TimestampModelSerializer
):
level_type
=
serializers
.
SlugRelatedField
(
read_only
=
True
,
slug_field
=
'name'
)
subjects
=
SubjectSerializer
(
many
=
True
)
prerequisites
=
PrerequisiteSerializer
(
many
=
True
)
expected_learning_items
=
serializers
.
SlugRelatedField
(
many
=
True
,
read_only
=
True
,
slug_field
=
'value'
)
image
=
ImageSerializer
()
video
=
VideoSerializer
()
owners
=
OrganizationSerializer
(
many
=
True
)
sponsors
=
OrganizationSerializer
(
many
=
True
)
course_runs
=
CourseRunSerializer
(
many
=
True
)
class
Meta
(
object
):
model
=
Course
fields
=
(
'key'
,
'title'
,
'short_description'
,
'full_description'
,
'level_type'
,
'subjects'
,
'prerequisites'
,
'expected_learning_items'
,
'image'
,
'video'
,
'owners'
,
'sponsors'
,
'modified'
,
'course_runs'
,
)
class
ContainedCoursesSerializer
(
serializers
.
Serializer
):
# pylint: disable=abstract-method
courses
=
serializers
.
DictField
(
child
=
serializers
.
BooleanField
(),
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
39214f4d
...
...
@@ -39,10 +39,8 @@ class CourseSerializerTests(TestCase):
course
=
CourseFactory
()
image
=
course
.
image
video
=
course
.
video
CourseRunFactory
.
create_batch
(
3
,
course
=
course
)
serializer
=
CourseSerializer
(
course
)
# path = reverse('api:v1:course-detail', kwargs={'key': course.key})
# request = RequestFactory().get(path)
# serializer = CourseSerializer(course, context={'request': request})
expected
=
{
'key'
:
course
.
key
,
...
...
@@ -57,7 +55,8 @@ class CourseSerializerTests(TestCase):
'video'
:
VideoSerializer
(
video
)
.
data
,
'owners'
:
[],
'sponsors'
:
[],
'modified'
:
json_date_format
(
course
.
modified
)
# pylint: disable=no-member
'modified'
:
json_date_format
(
course
.
modified
),
# pylint: disable=no-member
'course_runs'
:
CourseRunSerializer
(
course
.
course_runs
,
many
=
True
)
.
data
}
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
...
...
@@ -71,6 +70,7 @@ class CourseRunSerializerTests(TestCase):
serializer
=
CourseRunSerializer
(
course_run
)
expected
=
{
'course'
:
course_run
.
course
.
key
,
'key'
:
course_run
.
key
,
'title'
:
course_run
.
title
,
# pylint: disable=no-member
'short_description'
:
course_run
.
short_description
,
# pylint: disable=no-member
...
...
@@ -163,6 +163,7 @@ class OrganizationSerializerTests(TestCase):
serializer
=
OrganizationSerializer
(
organization
)
expected
=
{
'key'
:
organization
.
key
,
'name'
:
organization
.
name
,
'description'
:
organization
.
description
,
'homepage_url'
:
organization
.
homepage_url
,
...
...
@@ -202,6 +203,7 @@ class PersonSerializerTests(TestCase):
serializer
=
PersonSerializer
(
person
)
expected
=
{
'key'
:
person
.
key
,
'name'
:
person
.
name
,
'title'
:
person
.
title
,
'bio'
:
person
.
bio
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment