From d0e2f8e1d4cff0fe0b4078aa50320f5a741d5f72 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 14 Jan 2011 16:19:48 +0530 Subject: [PATCH] update api --- pandora/api/actions.py | 43 +++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/pandora/api/actions.py b/pandora/api/actions.py index 787a9f46e..b826692d3 100644 --- a/pandora/api/actions.py +++ b/pandora/api/actions.py @@ -5,7 +5,7 @@ import sys from django.conf import settings from ox.django.shortcuts import render_to_json_response, json_response - +from ox.utils import json def autodiscover(): #register api actions from all installed apps @@ -53,32 +53,41 @@ class ApiActions(dict): def api(request): ''' - returns list of all known api action - return {'status': {'code': int, 'text': string}, - 'data': {actions: ['api', 'hello', ...]}} + returns list of all known api actions + param data { + 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.sort() actions = {} for a in _actions: actions[a] = self.properties[a] + if docs: + actions[a]['doc'] = self.doc(a) response = json_response({'actions': actions}) return render_to_json_response(response) 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): return trim(self[f].__doc__)