forked from 0x2620/pandora
update api
This commit is contained in:
parent
6bc39ceada
commit
d0e2f8e1d4
1 changed files with 26 additions and 17 deletions
|
@ -5,7 +5,7 @@ import sys
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from ox.django.shortcuts import render_to_json_response, json_response
|
from ox.django.shortcuts import render_to_json_response, json_response
|
||||||
|
from ox.utils import json
|
||||||
|
|
||||||
def autodiscover():
|
def autodiscover():
|
||||||
#register api actions from all installed apps
|
#register api actions from all installed apps
|
||||||
|
@ -53,32 +53,41 @@ class ApiActions(dict):
|
||||||
|
|
||||||
def api(request):
|
def api(request):
|
||||||
'''
|
'''
|
||||||
returns list of all known api action
|
returns list of all known api actions
|
||||||
return {'status': {'code': int, 'text': string},
|
param data {
|
||||||
'data': {actions: ['api', 'hello', ...]}}
|
docs: bool
|
||||||
|
}
|
||||||
|
if docs is true, action properties contain docstrings
|
||||||
|
return {
|
||||||
|
status: {'code': int, 'text': string},
|
||||||
|
data: {
|
||||||
|
actions: {
|
||||||
|
'api': {
|
||||||
|
cache: true,
|
||||||
|
doc: 'recursion'
|
||||||
|
},
|
||||||
|
'hello': {
|
||||||
|
cache: true,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
'''
|
'''
|
||||||
|
data = json.loads(request.POST['data'])
|
||||||
|
docs = data.get('docs', False)
|
||||||
_actions = self.keys()
|
_actions = self.keys()
|
||||||
_actions.sort()
|
_actions.sort()
|
||||||
actions = {}
|
actions = {}
|
||||||
for a in _actions:
|
for a in _actions:
|
||||||
actions[a] = self.properties[a]
|
actions[a] = self.properties[a]
|
||||||
|
if docs:
|
||||||
|
actions[a]['doc'] = self.doc(a)
|
||||||
response = json_response({'actions': actions})
|
response = json_response({'actions': actions})
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
self.register(api)
|
self.register(api)
|
||||||
|
|
||||||
def apidoc(request):
|
|
||||||
'''
|
|
||||||
returns array of actions with documentation
|
|
||||||
'''
|
|
||||||
actions = self.keys()
|
|
||||||
actions.sort()
|
|
||||||
docs = {}
|
|
||||||
for f in actions:
|
|
||||||
docs[f] = self.doc(f)
|
|
||||||
return render_to_json_response(json_response({'actions': docs}))
|
|
||||||
|
|
||||||
self.register(apidoc)
|
|
||||||
|
|
||||||
def doc(self, f):
|
def doc(self, f):
|
||||||
return trim(self[f].__doc__)
|
return trim(self[f].__doc__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue