WIP django catalog admin

This commit is contained in:
Bill DeRusha
2016-04-19 11:08:29 -04:00
committed by Peter Fogg
parent ffdacc9129
commit 25df9db6ff
10 changed files with 305 additions and 4 deletions

View File

@@ -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)

View File

@@ -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
)

View File

@@ -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

View File

@@ -2,10 +2,14 @@
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
@@ -14,9 +18,11 @@ from oauth2_provider.models import get_application_model
from oauth2_provider.views import ApplicationRegistration
from edxmako.shortcuts import render_to_response
from edx_rest_api_client.client import EdxRestApiClient
from openedx.core.djangoapps.api_admin.decorators import require_api_access
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__)
@@ -115,3 +121,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)