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
3a051f35
Commit
3a051f35
authored
Mar 06, 2018
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add first paid seat sku to search
parent
c8b72d39
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
0 deletions
+23
-0
course_discovery/apps/api/serializers.py
+1
-0
course_discovery/apps/api/tests/test_serializers.py
+2
-0
course_discovery/apps/course_metadata/models.py
+8
-0
course_discovery/apps/course_metadata/search_indexes.py
+4
-0
course_discovery/apps/course_metadata/tests/test_models.py
+8
-0
No files found.
course_discovery/apps/api/serializers.py
View file @
3a051f35
...
...
@@ -58,6 +58,7 @@ COURSE_RUN_SEARCH_FIELDS = (
'number'
,
'seat_types'
,
'image_url'
,
'type'
,
'level_type'
,
'availability'
,
'published'
,
'partner'
,
'program_types'
,
'authoring_organization_uuids'
,
'subject_uuids'
,
'staff_uuids'
,
'mobile_available'
,
'logo_image_urls'
,
'aggregation_key'
,
'min_effort'
,
'max_effort'
,
'weeks_to_complete'
,
'has_enrollable_seats'
,
'first_enrollable_paid_seat_sku'
)
PROGRAM_FACET_FIELD_OPTIONS
=
{
...
...
course_discovery/apps/api/tests/test_serializers.py
View file @
3a051f35
...
...
@@ -1237,6 +1237,7 @@ class CourseRunSearchSerializerTests(ElasticsearchTestMixin, TestCase):
def
test_data
(
self
):
course_run
=
CourseRunFactory
(
transcript_languages
=
LanguageTag
.
objects
.
filter
(
code__in
=
[
'en-us'
,
'zh-cn'
]),
authoring_organizations
=
[
OrganizationFactory
()])
SeatFactory
.
create
(
course_run
=
course_run
,
type
=
'verified'
,
price
=
10
,
sku
=
'ABCDEF'
)
program
=
ProgramFactory
(
courses
=
[
course_run
.
course
])
self
.
reindex_courses
(
program
)
serializer
=
self
.
serialize_course_run
(
course_run
)
...
...
@@ -1276,6 +1277,7 @@ class CourseRunSearchSerializerTests(ElasticsearchTestMixin, TestCase):
'staff_uuids'
:
get_uuids
(
course_run
.
staff
.
all
()),
'aggregation_key'
:
'courserun:{}'
.
format
(
course_run
.
course
.
key
),
'has_enrollable_seats'
:
course_run
.
has_enrollable_seats
,
'first_enrollable_paid_seat_sku'
:
course_run
.
first_enrollable_paid_seat_sku
(),
}
assert
serializer
.
data
==
expected
...
...
course_discovery/apps/course_metadata/models.py
View file @
3a051f35
...
...
@@ -521,6 +521,14 @@ class CourseRun(TimeStampedModel):
"""
return
self
.
seats
.
exclude
(
type__in
=
Seat
.
SEATS_WITH_PREREQUISITES
)
.
filter
(
price__gt
=
0.0
)
def
first_enrollable_paid_seat_sku
(
self
):
seats
=
list
(
self
.
_enrollable_paid_seats
()
.
order_by
(
'upgrade_deadline'
))
if
not
seats
:
# Enrollable paid seats are not available for this CourseRun.
return
None
first_enrollable_paid_seat_sku
=
seats
[
0
]
.
sku
return
first_enrollable_paid_seat_sku
def
has_enrollable_paid_seats
(
self
):
"""
Return a boolean indicating whether or not enrollable paid Seats (Seats with price > 0 and no prerequisites)
...
...
course_discovery/apps/course_metadata/search_indexes.py
View file @
3a051f35
...
...
@@ -168,6 +168,7 @@ class CourseRunIndex(BaseCourseIndex, indexes.Indexable):
staff_uuids
=
indexes
.
MultiValueField
()
subject_uuids
=
indexes
.
MultiValueField
()
has_enrollable_paid_seats
=
indexes
.
BooleanField
(
null
=
False
)
first_enrollable_paid_seat_sku
=
indexes
.
CharField
(
null
=
True
)
paid_seat_enrollment_end
=
indexes
.
DateTimeField
(
null
=
True
)
license
=
indexes
.
MultiValueField
(
model_attr
=
'license'
,
faceted
=
True
)
has_enrollable_seats
=
indexes
.
BooleanField
(
model_attr
=
'has_enrollable_seats'
,
null
=
False
)
...
...
@@ -180,6 +181,9 @@ class CourseRunIndex(BaseCourseIndex, indexes.Indexable):
def
prepare_has_enrollable_paid_seats
(
self
,
obj
):
return
obj
.
has_enrollable_paid_seats
()
def
prepare_first_enrollable_paid_seat_sku
(
self
,
obj
):
return
obj
.
first_enrollable_paid_seat_sku
()
def
prepare_is_current_and_still_upgradeable
(
self
,
obj
):
return
obj
.
is_current_and_still_upgradeable
()
...
...
course_discovery/apps/course_metadata/tests/test_models.py
View file @
3a051f35
...
...
@@ -232,6 +232,14 @@ class CourseRunTests(TestCase):
factories
.
SeatFactory
.
create
(
course_run
=
course_run
,
type
=
seat_type
,
price
=
price
)
self
.
assertEqual
(
course_run
.
has_enrollable_paid_seats
(),
expected_result
)
def
test_first_enrollable_paid_seat_sku
(
self
):
"""
Verify that first_enrollable_paid_seat_sku returns sku of first paid seat.
"""
course_run
=
factories
.
CourseRunFactory
.
create
()
factories
.
SeatFactory
.
create
(
course_run
=
course_run
,
type
=
'verified'
,
price
=
10
,
sku
=
'ABCDEF'
)
self
.
assertEqual
(
course_run
.
first_enrollable_paid_seat_sku
(),
'ABCDEF'
)
@ddt.data
(
# Case 1: Return None when there are no enrollable paid Seats.
([(
'audit'
,
0
,
None
)],
'2016-12-31 00:00:00Z'
,
'2016-08-31 00:00:00Z'
,
None
),
...
...
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