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
bf5f5af7
Commit
bf5f5af7
authored
Feb 10, 2017
by
Douglas Hall
Committed by
Douglas Hall
Feb 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to filter Program list by a comma-separated list of ProgramType names
WL-766
parent
a3ae8b9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
0 deletions
+19
-0
course_discovery/apps/api/filters.py
+1
-0
course_discovery/apps/api/v1/tests/test_views/test_programs.py
+12
-0
course_discovery/apps/api/v1/views/programs.py
+6
-0
No files found.
course_discovery/apps/api/filters.py
View file @
bf5f5af7
...
@@ -156,6 +156,7 @@ class CourseRunFilter(FilterSetMixin, django_filters.FilterSet):
...
@@ -156,6 +156,7 @@ class CourseRunFilter(FilterSetMixin, django_filters.FilterSet):
class
ProgramFilter
(
FilterSetMixin
,
django_filters
.
FilterSet
):
class
ProgramFilter
(
FilterSetMixin
,
django_filters
.
FilterSet
):
marketable
=
django_filters
.
MethodFilter
()
marketable
=
django_filters
.
MethodFilter
()
type
=
django_filters
.
CharFilter
(
name
=
'type__name'
,
lookup_expr
=
'iexact'
)
type
=
django_filters
.
CharFilter
(
name
=
'type__name'
,
lookup_expr
=
'iexact'
)
types
=
CharListFilter
(
name
=
'type__slug'
,
lookup_expr
=
'in'
)
uuids
=
UUIDListFilter
()
uuids
=
UUIDListFilter
()
class
Meta
:
class
Meta
:
...
...
course_discovery/apps/api/v1/tests/test_views/test_programs.py
View file @
bf5f5af7
...
@@ -127,6 +127,18 @@ class ProgramViewSetTests(SerializationMixin, APITestCase):
...
@@ -127,6 +127,18 @@ class ProgramViewSetTests(SerializationMixin, APITestCase):
url
=
self
.
list_path
+
'?type=bar'
url
=
self
.
list_path
+
'?type=bar'
self
.
assert_list_results
(
url
,
[],
4
)
self
.
assert_list_results
(
url
,
[],
4
)
def
test_filter_by_types
(
self
):
""" Verify that the endpoint filters programs to those matching the provided ProgramType slugs. """
expected
=
ProgramFactory
.
create_batch
(
2
)
expected
.
reverse
()
type_slugs
=
[
p
.
type
.
slug
for
p
in
expected
]
url
=
self
.
list_path
+
'?types='
+
','
.
join
(
type_slugs
)
# Create a third program, which should be filtered out.
ProgramFactory
()
self
.
assert_list_results
(
url
,
expected
,
8
)
def
test_filter_by_uuids
(
self
):
def
test_filter_by_uuids
(
self
):
""" Verify that the endpoint filters programs to those matching the provided UUIDs. """
""" Verify that the endpoint filters programs to those matching the provided UUIDs. """
expected
=
ProgramFactory
.
create_batch
(
2
)
expected
=
ProgramFactory
.
create_batch
(
2
)
...
...
course_discovery/apps/api/v1/views/programs.py
View file @
bf5f5af7
...
@@ -77,6 +77,12 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
...
@@ -77,6 +77,12 @@ class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
type: integer
type: integer
paramType: query
paramType: query
multiple: false
multiple: false
- name: types
description: Filter by comma-separated list of program type slugs
required: false
type: string
paramType: query
multiple: false
"""
"""
return
super
(
ProgramViewSet
,
self
)
.
list
(
request
,
*
args
,
**
kwargs
)
return
super
(
ProgramViewSet
,
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