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
3756a28a
Commit
3756a28a
authored
Apr 19, 2016
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP django catalog admin
parent
db07e5d2
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
305 additions
and
4 deletions
+305
-4
lms/templates/admin/api_admin/catalog/change_form.html
+50
-0
lms/templates/admin/api_admin/catalog/change_list.html
+27
-0
lms/templates/api_admin/catalog_changeform.html
+49
-0
lms/templates/api_admin/catalog_changelist.html
+60
-0
lms/urls.py
+3
-0
openedx/core/djangoapps/api_admin/admin.py
+4
-1
openedx/core/djangoapps/api_admin/forms.py
+10
-0
openedx/core/djangoapps/api_admin/models.py
+21
-0
openedx/core/djangoapps/api_admin/views.py
+79
-2
openedx/core/lib/token_utils.py
+2
-1
No files found.
lms/templates/admin/api_admin/catalog/change_form.html
0 → 100644
View file @
3756a28a
{% extends "admin/base_site.html" %}
{% load admin_modify adminmedia %}
{% block extrahead %}
{{ block.super }}
{{ media }}
{% endblock %}
{% block extrastyle %}{{ block.super }}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% admin_media_prefix %}css/forms.css"
/>
{% endblock %}
{% block coltype %}colMS{% endblock %}
{% block bodyclass %} change-form{% endblock %}
{% block breadcrumbs %}
<div
class=
"breadcrumbs"
>
<a
href=
"../../../"
>
Home
</a>
›
<a
href=
"../../"
>
Api_Admin
</a>
›
<a
href=
"../"
>
Catalogs
</a>
›
{% if change %}
{{form.name}}
{% else %}
Add Catalog
{% endif %}
</div>
{% endblock %}
{% block content %}
<div
id=
"content-main"
>
{% block object-tools %}
{% endblock %}
<form
action=
"."
method=
"post"
enctype=
"multipart/form-data"
>
<fieldset
class=
"module aligned {{ fieldset.classes }}"
>
{% for field in form.visible_fields %}
<div
class=
"form-row"
>
{{ field.errors }}
{{ field.label_tag }}{{ field }}
{% if field.field.help_text %}
<p
class=
"help"
>
{{ field.field.help_text|safe }}
</p>
{% endif %}
</div>
{% endfor %}
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
</fieldset>
<input
type=
"submit"
value=
"Save"
/>
</form>
</div>
{% endblock %}
lms/templates/admin/api_admin/catalog/change_list.html
0 → 100644
View file @
3756a28a
{% extends "admin/base_site.html" %}
{% block extrahead %}
{{ block.super }}
{% endblock %}
{% block innercontent %}
<ul
class=
"object-tools"
>
<li>
<a
class=
"addlink"
href=
"add/"
>
Add Catalog
</a>
</li>
</ul>
<table
cellspacing=
"0"
style=
"margin-top: 20px;"
>
<thead>
<tr>
<th></th>
<th>
Name
</th>
</tr>
</thead>
{% for catalog in catalogs %}
<tr
class=
"{% cycle 'row1' 'row2' %}"
>
<td>
</td>
<td>
<a
href=
"{{catalog.id}}"
>
{{catalog.name}}
</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
lms/templates/api_admin/catalog_changeform.html
0 → 100644
View file @
3756a28a
{% extends "admin/base_site.html" %}
{% load admin_modify staticfiles %}
{% block extrahead %}
{{ block.super }}
{{ media }}
{% endblock %}
{% block extrastyle %}{{ block.super }}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'css/forms.css' %}"
/>
{% endblock %}
{% block coltype %}colMS{% endblock %}
{% block bodyclass %} change-form{% endblock %}
{% block breadcrumbs %}
<div
class=
"breadcrumbs"
>
<a
href=
"../../../"
>
Home
</a>
›
<a
href=
"../../"
>
Api_Admin
</a>
›
<a
href=
"../"
>
Catalogs
</a>
›
{% if change %}
{{form.name}}
{% else %}
Add Catalog
{% endif %}
</div>
{% endblock %}
{% block content %}
<div
id=
"content-main"
>
{% block object-tools %}
{% endblock %}
<form
action=
"."
method=
"post"
enctype=
"multipart/form-data"
>
{% csrf_token %}
<fieldset
class=
"module aligned {{ fieldset.classes }}"
>
{% for field in form.visible_fields %}
<div
class=
"form-row"
>
{{ field.errors }}
{{ field.label_tag }}{{ field }}
{% if field.field.help_text %}
<p
class=
"help"
>
{{ field.field.help_text|safe }}
</p>
{% endif %}
</div>
{% endfor %}
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
</fieldset>
<input
type=
"submit"
value=
"Save"
/>
</form>
</div>
{% endblock %}
lms/templates/api_admin/catalog_changelist.html
0 → 100644
View file @
3756a28a
{% extends "admin/base_site.html" %}
{% load i18n admin_urls static admin_list %}
{% block extrastyle %}
{{ block.super }}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
admin
/
css
/
changelists
.
css
"
%}"
/>
{% if cl.formset %}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
admin
/
css
/
forms
.
css
"
%}"
/>
{% endif %}
{% if cl.formset or action_form %}
<script
type=
"text/javascript"
src=
"{% url 'admin:jsi18n' %}"
></script>
{% endif %}
{{ media.css }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist
table
thead
th
:first-child
{
width
:
inherit
}
</style>
{% endif %}
{% endblock %}
{% block extrahead %}
{{ block.super }}
{{ media.js }}
{% endblock %}
{% block breadcrumbs %}
<div
class=
"breadcrumbs"
>
<a
href=
"../../../"
>
Home
</a>
›
<a
href=
"../../"
>
Api_Admin
</a>
›
Catalogs
</div>
{% endblock %}
{% block coltype %}flex{% endblock %}
{% block content %}
{% block innercontent %}
<ul
class=
"object-tools"
>
<li>
<a
class=
"addlink"
href=
"add/"
>
Add Catalog
</a>
</li>
</ul>
<table
cellspacing=
"0"
style=
"margin-top: 20px;"
>
<thead>
<tr>
<th></th>
<th>
Name
</th>
</tr>
</thead>
{% for catalog in catalogs %}
<tr
class=
"{% cycle 'row1' 'row2' %}"
>
<td>
</td>
<td>
<a
href=
"{{catalog.id}}"
>
{{catalog.name}}
</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
{% endblock %}
lms/urls.py
View file @
3756a28a
...
...
@@ -113,6 +113,9 @@ urlpatterns = (
# URLs for API access management
url
(
r'^api-admin/'
,
include
(
'openedx.core.djangoapps.api_admin.urls'
,
namespace
=
'api_admin'
)),
url
(
r'^admin/api_admin/catalog/add/$'
,
'openedx.core.djangoapps.api_admin.views.catalog_changeform'
),
url
(
r'^admin/api_admin/catalog/(?P<id>\d+)/$'
,
'openedx.core.djangoapps.api_admin.views.catalog_changeform'
),
url
(
r'^admin/api_admin/catalog/$'
,
'openedx.core.djangoapps.api_admin.views.catalog_changelist'
),
)
urlpatterns
+=
(
...
...
openedx/core/djangoapps/api_admin/admin.py
View file @
3756a28a
...
...
@@ -2,7 +2,7 @@
from
django.contrib
import
admin
from
config_models.admin
import
ConfigurationModelAdmin
from
openedx.core.djangoapps.api_admin.models
import
ApiAccessRequest
,
ApiAccessConfig
from
openedx.core.djangoapps.api_admin.models
import
ApiAccessRequest
,
ApiAccessConfig
,
Catalog
@admin.register
(
ApiAccessRequest
)
...
...
@@ -15,5 +15,8 @@ class ApiAccessRequestAdmin(admin.ModelAdmin):
readonly_fields
=
(
'user'
,
'website'
,
'reason'
,
'company_name'
,
'company_address'
,
'contacted'
,
)
exclude
=
(
'site'
,)
@admin.register
(
Catalog
)
class
CatalogAdmin
(
admin
.
ModelAdmin
):
name
=
"Catalog"
admin
.
site
.
register
(
ApiAccessConfig
,
ConfigurationModelAdmin
)
openedx/core/djangoapps/api_admin/forms.py
View file @
3756a28a
...
...
@@ -32,3 +32,13 @@ class ApiAccessRequestForm(forms.ModelForm):
# Get rid of the colons at the end of the field labels.
kwargs
.
setdefault
(
'label_suffix'
,
''
)
super
(
ApiAccessRequestForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
class
CatalogForm
(
forms
.
Form
):
id
=
forms
.
IntegerField
(
required
=
False
,
widget
=
forms
.
HiddenInput
)
name
=
forms
.
CharField
(
required
=
True
,
help_text
=
"The name of this catalog"
)
query
=
forms
.
CharField
(
required
=
True
,
help_text
=
"The query for courses to be returned by catalog"
,
widget
=
forms
.
Textarea
)
openedx/core/djangoapps/api_admin/models.py
View file @
3756a28a
...
...
@@ -179,3 +179,24 @@ def _send_decision_email(instance):
instance
.
contacted
=
True
except
SMTPException
:
log
.
exception
(
'Error sending API user notification email for request [
%
s].'
,
instance
.
id
)
class
CatalogManager
(
object
):
def
get
(
self
,
key
):
log
.
info
(
"GET api call:
%
s"
,
key
)
return
None
def
all
(
self
):
log
.
info
(
"ALL api call"
)
return
[]
def
filter
(
self
,
**
kwargs
):
log
.
info
(
"FILTER api call:
%
s"
,
kwargs
)
return
[]
class
Catalog
(
models
.
Model
):
objects
=
CatalogManager
()
class
Meta
:
managed
=
False
openedx/core/djangoapps/api_admin/views.py
View file @
3756a28a
...
...
@@ -2,17 +2,23 @@
import
logging
from
django.conf
import
settings
from
django.contrib.admin.views.decorators
import
staff_member_required
from
django.contrib.sites.shortcuts
import
get_current_site
from
django.core.urlresolvers
import
reverse_lazy
,
reverse
from
django.shortcuts
import
redirect
from
django.http
import
HttpResponseRedirect
from
django.shortcuts
import
redirect
,
render
from
django.template
import
RequestContext
from
django.utils.translation
import
ugettext
as
_
from
django.views.decorators.cache
import
never_cache
from
django.views.generic
import
View
from
django.views.generic.base
import
TemplateView
from
django.views.generic.edit
import
CreateView
from
edx_rest_api_client.client
import
EdxRestApiClient
from
edxmako.shortcuts
import
render_to_response
from
openedx.core.djangoapps.api_admin.forms
import
ApiAccessRequestForm
from
openedx.core.djangoapps.api_admin.forms
import
ApiAccessRequestForm
,
CatalogForm
from
openedx.core.djangoapps.api_admin.models
import
ApiAccessRequest
from
openedx.core.lib.token_utils
import
get_asymmetric_token
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -60,3 +66,74 @@ class ApiTosView(TemplateView):
"""View to show the API Terms of Service."""
template_name
=
'api_admin/terms_of_service.html'
@never_cache
@staff_member_required
def
catalog_changelist
(
request
):
# TODO: get catalogs
catalogs
=
[
{
'id'
:
'1'
,
'name'
:
'test1'
,
'query'
:
'*'
}
]
return
render
(
RequestContext
(
request
),
'api_admin/catalog_changelist.html'
,
{
'catalogs'
:
catalogs
,
}
)
@never_cache
@staff_member_required
def
catalog_changeform
(
request
,
id
=
None
):
# import pdb; pdb.set_trace()
if
request
.
method
==
'POST'
:
form
=
CatalogForm
(
request
.
POST
)
change
=
False
if
form
.
is_valid
():
if
id
is
None
:
log
.
info
(
"CREATE NEW CATALOGUE"
)
# create new catalog
else
:
change
=
True
log
.
info
(
"UPDATE CATALOGUE"
)
# update catalog
return
HttpResponseRedirect
(
'..'
)
else
:
if
id
is
None
:
# Create new catalog
change
=
False
form
=
CatalogForm
()
else
:
# Update existing catalog
change
=
True
catalog
=
{
'id'
:
'2'
,
'name'
:
'test2'
,
'query'
:
'test*'
}
# Get catalogs
form
=
CatalogForm
(
catalog
)
# del form.fields['hidden_field']
return
render
(
request
,
'api_admin/catalog_changeform.html'
,
{
'change'
:
change
,
'form'
:
form
,
}
)
def
catalog_client
(
user
):
token
=
get_asymmetric_token
(
user
,
'course-discovery'
)
return
EdxRestApiClient
(
"http://18.111.106.34:8008/api/v1/"
,
jwt
=
token
)
# from openedx.core.djangoapps.api_admin.views import catalog_client
# from django.contrib.auth.models import User
# user = User.objects.all()[1]
# c = catalog_client(user)
openedx/core/lib/token_utils.py
View file @
3756a28a
...
...
@@ -67,7 +67,7 @@ def get_id_token(user, client_name):
return
jwt
.
encode
(
payload
,
client
.
client_secret
)
def
get_asymmetric_token
(
user
):
def
get_asymmetric_token
(
user
,
client_id
):
"""Construct a JWT signed with this app's private key.
The JWT includes the following claims:
...
...
@@ -108,6 +108,7 @@ def get_asymmetric_token(user):
'iss'
:
settings
.
OAUTH_OIDC_ISSUER
,
'exp'
:
now
+
datetime
.
timedelta
(
seconds
=
expires_in
),
'iat'
:
now
,
'aud'
:
client_id
,
'sub'
:
anonymous_id_for_user
(
user
,
None
),
}
...
...
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