Commit 95e8dada by Piotr Mitros

Cleaned up schema to fully replace probe. There should be only one

parent 9e39e0d5
<html> <html>
<h1>Welcome to analytics!</h1> <h1>Welcome to analytics!</h1>
<ul> <ul>
<li> <a href="/probe?f=html">Probe</a> will give a list of views and queries. <li> <a href="/schema?f=html">schema</a> will give a list of views and queries.
<li> <a href="/event_properties">Event properties</a> will give a list of event properties. <li> <a href="/event_properties">Event properties</a> will give a list of event properties.
</ul> </ul>
Docs are on <a href=https://github.com/MITx/djanalytics>github</a>. Docs are on <a href=https://github.com/MITx/djanalytics>github</a>.
......
...@@ -4,7 +4,7 @@ urlpatterns = patterns('', ...@@ -4,7 +4,7 @@ urlpatterns = patterns('',
# Examples: # Examples:
url(r'^view/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_view'), url(r'^view/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_view'),
url(r'^query/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_query'), url(r'^query/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_query'),
url(r'^schema$', 'djanalytics.core.views.list_all_endpoints'), url(r'^schema$', 'djanalytics.core.views.schema'),
url(r'^probe$', 'djanalytics.core.views.handle_probe'), url(r'^probe$', 'djanalytics.core.views.handle_probe'),
url(r'^probe/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_probe'), url(r'^probe/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_probe'),
url(r'^probe/([A-Za-z_+]+)/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_probe'), url(r'^probe/([A-Za-z_+]+)/([A-Za-z_+]+)$', 'djanalytics.core.views.handle_probe'),
......
...@@ -36,44 +36,48 @@ def event_properties(request): ...@@ -36,44 +36,48 @@ def event_properties(request):
items.append("<di>{name}</di><dd>{doc}</dd>".format(**event_property_registry[key])) items.append("<di>{name}</di><dd>{doc}</dd>".format(**event_property_registry[key]))
return HttpResponse("<dl>"+"\n".join(items)+"</dl>") return HttpResponse("<dl>"+"\n".join(items)+"</dl>")
@auth.auth # We don't want to have two ways to get at this data
def handle_probe(request, cls=None, name = None): # @auth.auth
''' Handles probes for what types of modules are available, and # def handle_probe(request, cls=None, name = None):
what they do. Shown as, effectively, a big directory tree to the # ''' Handles probes for what types of modules are available, and
caller. # what they do. Shown as, effectively, a big directory tree to the
''' # caller.
error_message = "{0} not found in {1}." # '''
if cls == None: # error_message = "{0} not found in {1}."
l = ['view','query'] # if cls == None:
elif name == None: # l = ['view','query']
if cls in request_handlers: # elif name == None:
l = request_handlers[cls].keys() # if cls in request_handlers:
else: # l = request_handlers[cls].keys()
raise Http404(error_message.format(cls,request_handlers)) # else:
else: # raise Http404(error_message.format(cls,request_handlers))
if cls in request_handlers and name in request_handlers[cls]: # else:
l = [request_handlers[cls][name]['doc']] # if cls in request_handlers and name in request_handlers[cls]:
else: # l = [request_handlers[cls][name]['doc']]
raise Http404(error_message.format(cls+'/'+name,request_handlers)) # else:
if request.GET.get("f", "") == "html": # raise Http404(error_message.format(cls+'/'+name,request_handlers))
if not name: # if request.GET.get("f", "") == "html":
l = ["<li><a href={a}?f=html>{b}</a></li>".format(a=(cls or "probe")+"/"+i, b=i) for i in l] # if not name:
else: # l = ["<li><a href={a}?f=html>{b}</a></li>".format(a=(cls or "probe")+"/"+i, b=i) for i in l]
l = ["<p>".join(l)] # else:
return HttpResponse("".join(l), mimetype='text/html') # l = ["<p>".join(l)]
return HttpResponse("\n".join(l), mimetype='text/text') # return HttpResponse("".join(l), mimetype='text/html')
# return HttpResponse("\n".join(l), mimetype='text/text')
@auth.auth @auth.auth
def list_all_endpoints(request): def schema(request):
''' Returns all available views and queries as a JSON ''' Returns all available views and queries as a JSON
object. Alternative to the probe hierarchy. object.
''' '''
endpoints = [] endpoints = []
for cls in request_handlers: for cls in request_handlers:
for name in request_handlers[cls]: for name in request_handlers[cls]:
endpoints.append({'type' : request_handlers[cls][name]['category'], 'class': cls, 'name' : name}) rh = request_handlers[cls][name]
endpoints.append({'category' : rh['category'], 'class': cls, 'name' : name, 'doc' : rh['doc']})
if request.GET.get("f", "") == "html":
return HttpResponse("\n".join(sorted(["<dt><p><b>{class}/{name}</b> <i>{category}</i></dt><dd>{doc}</dd>".format(**rh) for rh in endpoints])))
return HttpResponse(json.dumps(endpoints)) return HttpResponse(json.dumps(endpoints))
def handle_request(cls, name, **kwargs): def handle_request(cls, name, **kwargs):
''' Generic code from handle_view and handle_query ''' ''' Generic code from handle_view and handle_query '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment