Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
c43d8e15
Commit
c43d8e15
authored
Jun 09, 2016
by
Peter Fogg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 500 error when searching for a user without catalogs.
ECOM-4653
parent
cfd16207
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
openedx/core/djangoapps/api_admin/tests/test_views.py
+7
-0
openedx/core/djangoapps/api_admin/views.py
+11
-5
No files found.
openedx/core/djangoapps/api_admin/tests/test_views.py
View file @
c43d8e15
...
...
@@ -279,6 +279,13 @@ class CatalogListViewTest(CatalogTest):
self
.
assertIn
(
catalog
.
name
,
response
.
content
.
decode
(
'utf-8'
))
@httpretty.activate
def
test_get_no_catalogs
(
self
):
"""Verify that the view works when no catalogs are set up."""
self
.
mock_catalog_api
(
'api/v1/catalogs/'
,
{},
status_code
=
404
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
@httpretty.activate
def
test_post
(
self
):
catalog_data
=
{
'name'
:
'test-catalog'
,
...
...
openedx/core/djangoapps/api_admin/views.py
View file @
c43d8e15
...
...
@@ -13,6 +13,7 @@ from django.views.generic.edit import CreateView
from
oauth2_provider.generators
import
generate_client_secret
,
generate_client_id
from
oauth2_provider.models
import
get_application_model
from
oauth2_provider.views
import
ApplicationRegistration
from
slumber.exceptions
import
HttpNotFoundError
from
edxmako.shortcuts
import
render_to_response
from
openedx.core.djangoapps.api_admin.decorators
import
require_api_access
...
...
@@ -140,11 +141,18 @@ class CatalogListView(View):
template
=
'api_admin/catalogs/list.html'
def
_get_catalogs
(
self
,
client
,
username
):
"""Retrieve catalogs for a user. Returns the empty list if none are found."""
try
:
response
=
client
.
api
.
v1
.
catalogs
.
get
(
username
=
username
)
return
[
Catalog
(
attributes
=
catalog
)
for
catalog
in
response
[
'results'
]]
except
HttpNotFoundError
:
return
[]
def
get
(
self
,
request
,
username
):
"""Display a list of a user's catalogs."""
client
=
course_discovery_api_client
(
request
.
user
)
response
=
client
.
api
.
v1
.
catalogs
.
get
(
username
=
username
)
catalogs
=
[
Catalog
(
attributes
=
catalog
)
for
catalog
in
response
[
'results'
]]
catalogs
=
self
.
_get_catalogs
(
client
,
username
)
return
render_to_response
(
self
.
template
,
{
'username'
:
username
,
'catalogs'
:
catalogs
,
...
...
@@ -157,10 +165,8 @@ class CatalogListView(View):
"""Create a new catalog for a user."""
form
=
CatalogForm
(
request
.
POST
)
client
=
course_discovery_api_client
(
request
.
user
)
if
not
form
.
is_valid
():
response
=
client
.
api
.
v1
.
catalogs
.
get
(
username
=
username
)
catalogs
=
[
Catalog
(
attributes
=
catalog
)
for
catalog
in
response
[
'results'
]]
catalogs
=
self
.
_get_catalogs
(
client
,
username
)
return
render_to_response
(
self
.
template
,
{
'form'
:
form
,
'catalogs'
:
catalogs
,
...
...
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