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
4b671e9b
Commit
4b671e9b
authored
Sep 27, 2016
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only include programs for which the course runs are not excluded
parent
f8a73cdb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletions
+25
-1
course_discovery/apps/api/serializers.py
+8
-1
course_discovery/apps/api/tests/test_serializers.py
+17
-0
No files found.
course_discovery/apps/api/serializers.py
View file @
4b671e9b
...
...
@@ -75,6 +75,7 @@ PREFETCH_FIELDS = {
'course__programs'
,
'course__programs__partner'
,
'course__programs__type'
,
'course__programs__excluded_course_runs'
,
'language'
,
'seats'
,
'seats__currency'
,
...
...
@@ -350,7 +351,13 @@ class CourseRunSerializer(TimestampModelSerializer):
class
CourseRunWithProgramsSerializer
(
CourseRunSerializer
):
"""A ``CourseRunSerializer`` which includes programs derived from parent course."""
programs
=
NestedProgramSerializer
(
many
=
True
)
programs
=
serializers
.
SerializerMethodField
()
def
get_programs
(
self
,
obj
):
programs
=
[
program
for
program
in
obj
.
programs
.
all
()
if
obj
.
id
not
in
(
run
.
id
for
run
in
program
.
excluded_course_runs
.
all
())]
return
NestedProgramSerializer
(
programs
,
many
=
True
)
.
data
class
Meta
(
CourseRunSerializer
.
Meta
):
model
=
CourseRun
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
4b671e9b
...
...
@@ -190,6 +190,23 @@ class CourseRunWithProgramsSerializerTests(TestCase):
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
def
test_data_excluded_course_run
(
self
):
"""
If a course run is excluded on a program, that program should not be
returned for that course run on the course run endpoint.
"""
request
=
make_request
()
course_run
=
CourseRunFactory
()
serializer_context
=
{
'request'
:
request
}
serializer
=
CourseRunWithProgramsSerializer
(
course_run
,
context
=
serializer_context
)
ProgramFactory
(
courses
=
[
course_run
.
course
],
excluded_course_runs
=
[
course_run
])
expected
=
CourseRunSerializer
(
course_run
,
context
=
serializer_context
)
.
data
expected
.
update
({
'programs'
:
[],
})
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
class
FlattenedCourseRunWithCourseSerializerTests
(
TestCase
):
# pragma: no cover
def
serialize_seats
(
self
,
course_run
):
...
...
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