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
372c59e4
Commit
372c59e4
authored
Jun 16, 2016
by
Clinton Blackburn
Committed by
Clinton Blackburn
Jun 16, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added links to download catalog CSVs in API admin tool
ECOM-4729
parent
ecf44bbe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
30 deletions
+40
-30
lms/templates/api_admin/catalogs/edit.html
+6
-0
lms/templates/api_admin/catalogs/list.html
+4
-1
openedx/core/djangoapps/api_admin/views.py
+30
-29
No files found.
lms/templates/api_admin/catalogs/edit.html
View file @
372c59e4
...
...
@@ -23,6 +23,12 @@ from django.utils.translation import ugettext as _
<div
id=
"api-access-wrapper"
>
<h1
id=
"api-header"
>
${catalog.name}
</h1>
<p>
<a
href=
"${'{root}/{id}/csv/'.format(root=catalog_api_catalog_endpoint, id=catalog.id)}"
target=
"_blank"
>
${_("Download CSV")}
</a>
</p>
<div
class=
"catalog-body"
>
<div
class=
"api-form-container"
>
<form
class=
"api-form"
id=
"catalog-update"
action=
"${reverse('api_admin:catalog-edit', args=(catalog.id,))}"
method=
"post"
>
...
...
lms/templates/api_admin/catalogs/list.html
View file @
372c59e4
...
...
@@ -25,7 +25,10 @@ CatalogPreviewFactory({
<ul>
% for catalog in catalogs:
<li>
<a
href=
"${reverse('api_admin:catalog-edit', args=(catalog.id,))}"
>
${catalog.name}
</a>
<a
href=
"${reverse('api_admin:catalog-edit', args=(catalog.id,))}"
>
${catalog.name}
</a>
(
<a
href=
"${'{root}/{id}/csv/'.format(root=catalog_api_catalog_endpoint, id=catalog.id)}"
target=
"_blank"
>
${_("Download CSV")}
</a>
)
</li>
% endfor
</ul>
...
...
openedx/core/djangoapps/api_admin/views.py
View file @
372c59e4
...
...
@@ -6,7 +6,6 @@ from django.contrib.sites.shortcuts import get_current_site
from
django.core.urlresolvers
import
reverse_lazy
,
reverse
from
django.http.response
import
JsonResponse
from
django.shortcuts
import
redirect
from
django.utils.translation
import
ugettext
as
_
from
django.views.generic
import
View
from
django.views.generic.base
import
TemplateView
from
django.views.generic.edit
import
CreateView
...
...
@@ -149,31 +148,30 @@ class CatalogListView(View):
except
HttpNotFoundError
:
return
[]
def
get
(
self
,
request
,
username
):
"""Display a list of a user's catalogs."""
client
=
course_discovery_api_client
(
request
.
user
)
catalogs
=
self
.
_get_catalogs
(
client
,
username
)
return
render_to_response
(
self
.
template
,
{
def
get_context_data
(
self
,
client
,
username
,
form
):
""" Retrieve context data for the template. """
return
{
'username'
:
username
,
'catalogs'
:
catalogs
,
'form'
:
CatalogForm
(
initial
=
{
'viewers'
:
[
username
]})
,
'catalogs'
:
self
.
_get_catalogs
(
client
,
username
)
,
'form'
:
form
,
'preview_url'
:
reverse
(
'api_admin:catalog-preview'
),
'catalog_api_catalog_endpoint'
:
client
.
catalogs
.
url
()
.
rstrip
(
'/'
),
'catalog_api_url'
:
client
.
courses
.
url
(),
})
}
def
get
(
self
,
request
,
username
):
"""Display a list of a user's catalogs."""
client
=
course_discovery_api_client
(
request
.
user
)
form
=
CatalogForm
(
initial
=
{
'viewers'
:
[
username
]})
return
render_to_response
(
self
.
template
,
self
.
get_context_data
(
client
,
username
,
form
))
def
post
(
self
,
request
,
username
):
"""Create a new catalog for a user."""
form
=
CatalogForm
(
request
.
POST
)
client
=
course_discovery_api_client
(
request
.
user
)
if
not
form
.
is_valid
():
catalogs
=
self
.
_get_catalogs
(
client
,
username
)
return
render_to_response
(
self
.
template
,
{
'form'
:
form
,
'catalogs'
:
catalogs
,
'username'
:
username
,
'preview_url'
:
reverse
(
'api_admin:catalog-preview'
),
'catalog_api_url'
:
client
.
courses
.
url
(),
},
status
=
400
)
return
render_to_response
(
self
.
template
,
self
.
get_context_data
(
client
,
username
,
form
),
status
=
400
)
attrs
=
form
.
instance
.
attributes
catalog
=
client
.
catalogs
.
post
(
attrs
)
...
...
@@ -183,18 +181,26 @@ class CatalogListView(View):
class
CatalogEditView
(
View
):
"""View to edit an individual catalog."""
template_name
=
'api_admin/catalogs/edit.html'
def
get_context_data
(
self
,
catalog
,
form
,
client
):
""" Retrieve context data for the template. """
return
{
'catalog'
:
catalog
,
'form'
:
form
,
'preview_url'
:
reverse
(
'api_admin:catalog-preview'
),
'catalog_api_url'
:
client
.
courses
.
url
(),
'catalog_api_catalog_endpoint'
:
client
.
catalogs
.
url
()
.
rstrip
(
'/'
),
}
def
get
(
self
,
request
,
catalog_id
):
"""Display a form to edit this catalog."""
client
=
course_discovery_api_client
(
request
.
user
)
response
=
client
.
catalogs
(
catalog_id
)
.
get
()
catalog
=
Catalog
(
attributes
=
response
)
form
=
CatalogForm
(
instance
=
catalog
)
return
render_to_response
(
'api_admin/catalogs/edit.html'
,
{
'catalog'
:
catalog
,
'form'
:
form
,
'preview_url'
:
reverse
(
'api_admin:catalog-preview'
),
'catalog_api_url'
:
client
.
courses
.
url
(),
})
return
render_to_response
(
self
.
template_name
,
self
.
get_context_data
(
catalog
,
form
,
client
))
def
post
(
self
,
request
,
catalog_id
):
"""Update or delete this catalog."""
...
...
@@ -206,12 +212,7 @@ class CatalogEditView(View):
if
not
form
.
is_valid
():
response
=
client
.
catalogs
(
catalog_id
)
.
get
()
catalog
=
Catalog
(
attributes
=
response
)
return
render_to_response
(
'api_admin/catalogs/edit.html'
,
{
'catalog'
:
catalog
,
'form'
:
form
,
'preview_url'
:
reverse
(
'api_admin:catalog-preview'
),
'catalog_api_url'
:
client
.
courses
.
url
(),
},
status
=
400
)
return
render_to_response
(
self
.
template_name
,
self
.
get_context_data
(
catalog
,
form
,
client
),
status
=
400
)
catalog
=
client
.
catalogs
(
catalog_id
)
.
patch
(
form
.
instance
.
attributes
)
return
redirect
(
reverse
(
'api_admin:catalog-edit'
,
kwargs
=
{
'catalog_id'
:
catalog
[
'id'
]}))
...
...
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