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
e7c67e1a
Commit
e7c67e1a
authored
Mar 09, 2017
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add marketable_enrollable_course_runs_with_archived param to programs
ECOM-7262
parent
53572754
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
10 deletions
+62
-10
course_discovery/apps/api/serializers.py
+12
-5
course_discovery/apps/api/tests/test_serializers.py
+39
-0
course_discovery/apps/api/v1/views/programs.py
+11
-5
No files found.
course_discovery/apps/api/serializers.py
View file @
e7c67e1a
...
...
@@ -642,10 +642,18 @@ class MinimalProgramSerializer(serializers.ModelSerializer):
read_only_fields
=
(
'uuid'
,
'marketing_url'
,
'banner_image'
)
def
get_courses
(
self
,
program
):
course_runs
=
list
(
program
.
course_runs
)
if
self
.
context
.
get
(
'marketable_enrollable_course_runs_with_archived'
):
marketable_enrollable_course_runs
=
set
()
for
course
in
program
.
courses
.
all
():
marketable_enrollable_course_runs
.
update
(
course
.
course_runs
.
marketable
()
.
enrollable
())
course_runs
=
list
(
set
(
course_runs
)
.
intersection
(
marketable_enrollable_course_runs
))
if
program
.
order_courses_by_start_date
:
courses
,
course_runs
=
self
.
sort_courses
(
program
)
courses
=
self
.
sort_courses
(
program
,
course_runs
)
else
:
courses
,
course_runs
=
program
.
courses
.
all
(),
list
(
program
.
course_runs
)
courses
=
program
.
courses
.
all
(
)
course_serializer
=
MinimalProgramCourseSerializer
(
courses
,
...
...
@@ -662,7 +670,7 @@ class MinimalProgramSerializer(serializers.ModelSerializer):
return
course_serializer
.
data
def
sort_courses
(
self
,
program
):
def
sort_courses
(
self
,
program
,
course_runs
):
"""
Sorting by enrollment start then by course start yields a list ordered by course start, with
ties broken by enrollment start. This works because Python sorting is stable: two objects with
...
...
@@ -672,7 +680,6 @@ class MinimalProgramSerializer(serializers.ModelSerializer):
course_runs should never be empty. If it is, key functions in this method attempting to find the
min of an empty sequence will raise a ValueError.
"""
course_runs
=
list
(
program
.
course_runs
)
def
min_run_enrollment_start
(
course
):
# Enrollment starts may be empty. When this is the case, we make the same assumption as
...
...
@@ -715,7 +722,7 @@ class MinimalProgramSerializer(serializers.ModelSerializer):
courses
.
sort
(
key
=
min_run_enrollment_start
)
courses
.
sort
(
key
=
min_run_start
)
return
courses
,
course_runs
return
courses
class
ProgramSerializer
(
MinimalProgramSerializer
):
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
e7c67e1a
...
...
@@ -892,6 +892,45 @@ class ProgramSerializerTests(MinimalProgramSerializerTests):
course_run_with_seats
=
program_with_seats
[
'courses'
][
0
][
'course_runs'
][
0
]
assert
'seats'
in
course_run_with_seats
def
test_marketable_enrollable_course_runs_with_archived
(
self
):
""" Test that the marketable_enrollable_course_runs_with_archived flag hides course runs
that are not marketable or enrollable
"""
course
=
CourseFactory
()
CourseRunFactory
(
status
=
CourseRunStatus
.
Unpublished
,
course
=
course
)
marketable_enrollable_run
=
CourseRunFactory
(
status
=
CourseRunStatus
.
Published
,
end
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
+
datetime
.
timedelta
(
days
=
10
),
enrollment_start
=
None
,
enrollment_end
=
None
,
course
=
course
)
SeatFactory
(
course_run
=
marketable_enrollable_run
)
program
=
ProgramFactory
(
courses
=
[
course
])
request
=
make_request
()
serializer
=
self
.
serializer_class
(
program
,
context
=
{
'request'
:
request
,
'marketable_enrollable_course_runs_with_archived'
:
True
}
)
expected
=
MinimalProgramCourseSerializer
(
[
course
],
many
=
True
,
context
=
{
'request'
:
request
,
'program'
:
program
,
'course_runs'
:
[
marketable_enrollable_run
]
}
)
.
data
assert
len
(
expected
[
0
][
'course_runs'
])
==
1
assert
sorted
(
serializer
.
data
[
'courses'
][
0
][
'course_runs'
],
key
=
lambda
x
:
x
[
'key'
])
==
\
sorted
(
expected
[
0
][
'course_runs'
],
key
=
lambda
x
:
x
[
'key'
])
class
ProgramTypeSerializerTests
(
TestCase
):
serializer_class
=
ProgramTypeSerializer
...
...
course_discovery/apps/api/v1/views/programs.py
View file @
e7c67e1a
...
...
@@ -34,11 +34,10 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
def
get_serializer_context
(
self
,
*
args
,
**
kwargs
):
context
=
super
()
.
get_serializer_context
(
*
args
,
**
kwargs
)
context
.
update
({
'published_course_runs_only'
:
get_query_param
(
self
.
request
,
'published_course_runs_only'
),
'exclude_utm'
:
get_query_param
(
self
.
request
,
'exclude_utm'
),
'use_full_course_serializer'
:
get_query_param
(
self
.
request
,
'use_full_course_serializer'
),
})
query_params
=
[
'exclude_utm'
,
'use_full_course_serializer'
,
'published_course_runs_only'
,
'marketable_enrollable_course_runs_with_archived'
]
for
query_param
in
query_params
:
context
[
query_param
]
=
get_query_param
(
self
.
request
,
query_param
)
return
context
...
...
@@ -65,6 +64,13 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
type: integer
paramType: query
mulitple: false
- name: marketable_enrollable_course_runs_with_archived
description: Restrict returned course runs to those that are published, have seats,
and can be enrolled in now. Includes archived courses.
required: false
type: integer
paramType: query
mulitple: false
- name: exclude_utm
description: Exclude UTM parameters from marketing URLs.
required: false
...
...
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