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
e46a8dfd
Commit
e46a8dfd
authored
Aug 17, 2017
by
tasawernawaz
Committed by
Tasawer Nawaz
Aug 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exclude retired programs from course run api
LEARNER-2281
parent
c0faf2f2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
course_discovery/apps/api/serializers.py
+4
-0
course_discovery/apps/api/tests/test_serializers.py
+21
-0
course_discovery/apps/api/v1/views/course_runs.py
+7
-0
No files found.
course_discovery/apps/api/serializers.py
View file @
e46a8dfd
...
...
@@ -502,6 +502,10 @@ class CourseRunWithProgramsSerializer(CourseRunSerializer):
if
not
self
.
context
.
get
(
'include_unpublished_programs'
):
programs
=
[
program
for
program
in
programs
if
program
.
status
!=
ProgramStatus
.
Unpublished
]
# If flag is not set, remove programs from list that are retired
if
not
self
.
context
.
get
(
'include_retired_programs'
):
programs
=
[
program
for
program
in
programs
if
program
.
status
!=
ProgramStatus
.
Retired
]
return
NestedProgramSerializer
(
programs
,
many
=
True
)
.
data
class
Meta
(
CourseRunSerializer
.
Meta
):
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
e46a8dfd
...
...
@@ -359,6 +359,27 @@ class CourseRunWithProgramsSerializerTests(TestCase):
NestedProgramSerializer
([
unpublished_program
],
many
=
True
,
context
=
self
.
serializer_context
)
.
data
)
def
test_exclude_retired_program
(
self
):
"""
If a program is retired, that program should not be returned on the course run endpoint by default.
"""
ProgramFactory
(
courses
=
[
self
.
course_run
.
course
],
status
=
ProgramStatus
.
Retired
)
serializer
=
CourseRunWithProgramsSerializer
(
self
.
course_run
,
context
=
self
.
serializer_context
)
self
.
assertEqual
(
serializer
.
data
[
'programs'
],
[])
def
test_include_retired_programs
(
self
):
"""
If a program is retired, that program should only be returned on the course run endpoint if we are
sending the 'include_retired_programs' flag.
"""
retired_program
=
ProgramFactory
(
courses
=
[
self
.
course_run
.
course
],
status
=
ProgramStatus
.
Retired
)
self
.
serializer_context
[
'include_retired_programs'
]
=
1
serializer
=
CourseRunWithProgramsSerializer
(
self
.
course_run
,
context
=
self
.
serializer_context
)
self
.
assertEqual
(
serializer
.
data
[
'programs'
],
NestedProgramSerializer
([
retired_program
],
many
=
True
,
context
=
self
.
serializer_context
)
.
data
)
class
FlattenedCourseRunWithCourseSerializerTests
(
TestCase
):
# pragma: no cover
def
serialize_seats
(
self
,
course_run
):
...
...
course_discovery/apps/api/v1/views/course_runs.py
View file @
e46a8dfd
...
...
@@ -59,6 +59,7 @@ class CourseRunViewSet(viewsets.ModelViewSet):
'exclude_utm'
:
get_query_param
(
self
.
request
,
'exclude_utm'
),
'include_deleted_programs'
:
get_query_param
(
self
.
request
,
'include_deleted_programs'
),
'include_unpublished_programs'
:
get_query_param
(
self
.
request
,
'include_unpublished_programs'
),
'include_retired_programs'
:
get_query_param
(
self
.
request
,
'include_retired_programs'
),
})
return
context
...
...
@@ -117,6 +118,12 @@ class CourseRunViewSet(viewsets.ModelViewSet):
type: integer
paramType: query
multiple: false
- name: include_retired_programs
description: Will include retired programs in the associated programs array
required: false
type: integer
paramType: query
multiple: false
"""
return
super
(
CourseRunViewSet
,
self
)
.
list
(
request
,
*
args
,
**
kwargs
)
...
...
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