Commit 6e1b08e4 by Piotr Mitros

Moved schema helper into registry

parent 5794cae1
......@@ -69,8 +69,8 @@ class embed():
url = self._baseurl+"schema"
schema = json.loads(requests.get(url).content)
else:
import djanalytics.core.views
schema = djanalytics.core.views.schema_helper()
import djanalytics.core.registry
schema = djanalytics.core.registry.schema_helper()
def __getattr__(self, attr):
## Disallow internal. This is necessary both for analytics,
......
......@@ -89,3 +89,12 @@ def register_event_property(f, name, description):
if not description:
description = str(f.func_doc)
event_property_registry[name] = {'function': f, 'name': name, 'doc': description}
def schema_helper():
endpoints = []
for cls in request_handlers:
for name in request_handlers[cls]:
rh = request_handlers[cls][name]
endpoints.append({'category' : rh['category'], 'class': cls, 'name' : name, 'doc' : rh['doc']})
return endpoints
......@@ -36,19 +36,12 @@ def event_properties(request):
items.append("<di>{name}</di><dd>{doc}</dd>".format(**event_property_registry[key]))
return HttpResponse("<dl>"+"\n".join(items)+"</dl>")
def schema_helper():
endpoints = []
for cls in request_handlers:
for name in request_handlers[cls]:
rh = request_handlers[cls][name]
endpoints.append({'category' : rh['category'], 'class': cls, 'name' : name, 'doc' : rh['doc']})
return endpoints
@auth.auth
def schema(request):
''' Returns all available views and queries as a JSON
object.
'''
from registry import schema_helper
endpoints = schema_helper()
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])))
......
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