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
edf1589e
Commit
edf1589e
authored
Aug 23, 2016
by
Clinton Blackburn
Committed by
GitHub
Aug 23, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #273 from edx/clintonb/facet-seat-type
Added facet for seat types
parents
52587ad7
561d4d7d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
12 deletions
+32
-12
course_discovery/apps/api/serializers.py
+3
-0
course_discovery/apps/course_metadata/models.py
+10
-4
course_discovery/apps/course_metadata/search_indexes.py
+1
-0
course_discovery/apps/course_metadata/tests/test_models.py
+18
-8
No files found.
course_discovery/apps/api/serializers.py
View file @
edf1589e
...
...
@@ -33,6 +33,7 @@ COURSE_RUN_FACET_FIELD_OPTIONS = {
'pacing_type'
:
{},
'content_type'
:
{},
'type'
:
{},
'seat_types'
:
{},
}
COURSE_RUN_FACET_FIELD_QUERIES
=
{
...
...
@@ -50,6 +51,8 @@ COURSE_RUN_SEARCH_FIELDS = (
PROGRAM_FACET_FIELD_OPTIONS
=
{
'category'
:
{},
'status'
:
{},
'type'
:
{},
'seat_types'
:
{},
}
BASE_PROGRAM_FIELDS
=
(
...
...
course_discovery/apps/course_metadata/models.py
View file @
edf1589e
...
...
@@ -632,11 +632,17 @@ class Program(TimeStampedModel):
return
set
(
subjects
)
@property
def
price_range
s
(
self
):
def
seat
s
(
self
):
applicable_seat_types
=
self
.
type
.
applicable_seat_types
.
values_list
(
'slug'
,
flat
=
True
)
seats
=
Seat
.
objects
.
filter
(
course_run__in
=
self
.
course_runs
,
type__in
=
applicable_seat_types
)
\
.
values
(
'currency'
)
\
.
annotate
(
models
.
Min
(
'price'
),
models
.
Max
(
'price'
))
return
Seat
.
objects
.
filter
(
course_run__in
=
self
.
course_runs
,
type__in
=
applicable_seat_types
)
@property
def
seat_types
(
self
):
return
set
(
self
.
seats
.
values_list
(
'type'
,
flat
=
True
))
@property
def
price_ranges
(
self
):
seats
=
self
.
seats
.
values
(
'currency'
)
.
annotate
(
models
.
Min
(
'price'
),
models
.
Max
(
'price'
))
price_ranges
=
[]
for
seat
in
seats
:
...
...
course_discovery/apps/course_metadata/search_indexes.py
View file @
edf1589e
...
...
@@ -151,6 +151,7 @@ class ProgramIndex(BaseIndex, indexes.Indexable, OrganizationsMixin):
status
=
indexes
.
CharField
(
model_attr
=
'status'
,
faceted
=
True
)
partner
=
indexes
.
CharField
(
model_attr
=
'partner__short_code'
,
null
=
True
,
faceted
=
True
)
start
=
indexes
.
DateTimeField
(
model_attr
=
'start'
,
null
=
True
,
faceted
=
True
)
seat_types
=
indexes
.
MultiValueField
(
model_attr
=
'seat_types'
,
null
=
True
,
faceted
=
True
)
def
prepare_organizations
(
self
,
obj
):
return
self
.
prepare_authoring_organizations
(
obj
)
+
self
.
prepare_credit_backing_organizations
(
obj
)
...
...
course_discovery/apps/course_metadata/tests/test_models.py
View file @
edf1589e
...
...
@@ -262,6 +262,19 @@ class ProgramTests(TestCase):
self
.
excluded_course_run
=
factories
.
CourseRunFactory
(
course
=
self
.
courses
[
0
])
self
.
program
=
factories
.
ProgramFactory
(
courses
=
self
.
courses
,
excluded_course_runs
=
[
self
.
excluded_course_run
])
def
create_program_with_seats
(
self
):
currency
=
Currency
.
objects
.
get
(
code
=
'USD'
)
course_run
=
factories
.
CourseRunFactory
()
factories
.
SeatFactory
(
type
=
'audit'
,
currency
=
currency
,
course_run
=
course_run
,
price
=
0
)
factories
.
SeatFactory
(
type
=
'credit'
,
currency
=
currency
,
course_run
=
course_run
,
price
=
600
)
factories
.
SeatFactory
(
type
=
'verified'
,
currency
=
currency
,
course_run
=
course_run
,
price
=
100
)
applicable_seat_types
=
SeatType
.
objects
.
filter
(
slug__in
=
[
'credit'
,
'verified'
])
program_type
=
factories
.
ProgramTypeFactory
(
applicable_seat_types
=
applicable_seat_types
)
return
factories
.
ProgramFactory
(
type
=
program_type
,
courses
=
[
course_run
.
course
])
def
test_str
(
self
):
"""Verify that a program is properly converted to a str."""
self
.
assertEqual
(
str
(
self
.
program
),
self
.
program
.
title
)
...
...
@@ -326,14 +339,7 @@ class ProgramTests(TestCase):
self
.
assertIsNone
(
self
.
program
.
start
)
def
test_price_ranges
(
self
):
currency
=
Currency
.
objects
.
get
(
code
=
'USD'
)
course_run
=
factories
.
CourseRunFactory
()
factories
.
SeatFactory
(
type
=
'audit'
,
currency
=
currency
,
course_run
=
course_run
,
price
=
0
)
factories
.
SeatFactory
(
type
=
'credit'
,
currency
=
currency
,
course_run
=
course_run
,
price
=
600
)
factories
.
SeatFactory
(
type
=
'verified'
,
currency
=
currency
,
course_run
=
course_run
,
price
=
100
)
applicable_seat_types
=
SeatType
.
objects
.
filter
(
slug__in
=
[
'credit'
,
'verified'
])
program_type
=
factories
.
ProgramTypeFactory
(
applicable_seat_types
=
applicable_seat_types
)
program
=
factories
.
ProgramFactory
(
type
=
program_type
,
courses
=
[
course_run
.
course
])
program
=
self
.
create_program_with_seats
()
expected_price_ranges
=
[{
'currency'
:
'USD'
,
'min'
:
Decimal
(
100
),
'max'
:
Decimal
(
600
)}]
self
.
assertEqual
(
program
.
price_ranges
,
expected_price_ranges
)
...
...
@@ -357,6 +363,10 @@ class ProgramTests(TestCase):
self
.
assertIsNotNone
(
sized_file
)
self
.
assertIn
(
image_url_prefix
,
sized_file
.
url
)
def
test_seat_types
(
self
):
program
=
self
.
create_program_with_seats
()
self
.
assertEqual
(
program
.
seat_types
,
set
([
'credit'
,
'verified'
]))
class
PersonSocialNetworkTests
(
TestCase
):
"""Tests of the PersonSocialNetwork model."""
...
...
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