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
fa251757
Commit
fa251757
authored
Aug 02, 2017
by
Clinton Blackburn
Committed by
Clinton Blackburn
Aug 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for filtering people by slug
LEARNER-2154
parent
8bf70642
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
course_discovery/apps/api/filters.py
+7
-1
course_discovery/apps/api/v1/tests/test_views/test_people.py
+8
-0
course_discovery/apps/api/v1/views/people.py
+4
-1
No files found.
course_discovery/apps/api/filters.py
View file @
fa251757
...
...
@@ -13,7 +13,7 @@ from rest_framework.exceptions import NotFound, PermissionDenied
from
course_discovery.apps.api.utils
import
cast2int
from
course_discovery.apps.course_metadata.choices
import
ProgramStatus
from
course_discovery.apps.course_metadata.models
import
Course
,
CourseRun
,
Organization
,
Program
from
course_discovery.apps.course_metadata.models
import
Course
,
CourseRun
,
Organization
,
P
erson
,
P
rogram
logger
=
logging
.
getLogger
(
__name__
)
User
=
get_user_model
()
...
...
@@ -172,3 +172,9 @@ class OrganizationFilter(filters.FilterSet):
class
Meta
:
model
=
Organization
fields
=
(
'tags'
,
'uuids'
,)
class
PersonFilter
(
filters
.
FilterSet
):
class
Meta
:
model
=
Person
fields
=
(
'slug'
,)
course_discovery/apps/api/v1/tests/test_views/test_people.py
View file @
fa251757
...
...
@@ -125,6 +125,14 @@ class PersonViewSetTests(SerializationMixin, SiteMixin, APITestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertListEqual
(
response
.
data
[
'results'
],
self
.
serialize_person
(
Person
.
objects
.
all
(),
many
=
True
))
def
test_list_filter_by_slug
(
self
):
""" Verify the endpoint allows people to be filtered by slug. """
person
=
PersonFactory
()
url
=
'{root}?slug={slug}'
.
format
(
root
=
self
.
people_list_url
,
slug
=
person
.
slug
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertListEqual
(
response
.
data
[
'results'
],
self
.
serialize_person
([
person
],
many
=
True
))
def
test_create_without_waffle_switch
(
self
):
""" Verify endpoint shows error message if waffle switch is disabled. """
toggle_switch
(
'publish_person_to_marketing_site'
,
False
)
...
...
course_discovery/apps/api/v1/views/people.py
View file @
fa251757
import
logging
import
waffle
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework
import
status
,
viewsets
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.response
import
Response
from
course_discovery.apps.api
import
serializers
from
course_discovery.apps.api
import
filters
,
serializers
from
course_discovery.apps.api.pagination
import
PageNumberPagination
from
course_discovery.apps.course_metadata.exceptions
import
MarketingSiteAPIClientException
,
PersonToMarketingException
...
...
@@ -18,6 +19,8 @@ logger = logging.getLogger(__name__)
class
PersonViewSet
(
viewsets
.
ModelViewSet
):
""" PersonSerializer resource. """
filter_backends
=
(
DjangoFilterBackend
,)
filter_class
=
filters
.
PersonFilter
lookup_field
=
'uuid'
lookup_value_regex
=
'[0-9a-f-]+'
permission_classes
=
(
IsAuthenticated
,)
...
...
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