moksha/middleware/connector.py | 23 ++++++++++++++++++++--- moksha/public/javascript/moksha.js | 15 +++++++++++++++ moksha/public/javascript/ui/moksha.ui.grid.js | 3 +-- 3 files changed, 36 insertions(+), 5 deletions(-)
New commits: commit 33f5f1511ba94cc7b0b7587034f720b6a2a71e7c Merge: 39b2758... 4271164... Author: John (J5) Palmieri johnp@redhat.com Date: Thu Apr 2 16:19:49 2009 -0400
Merge branch 'master' of git+ssh://johnp@git.fedorahosted.org/git/moksha
commit 39b275873f879a5e1ed64763af8eb2ffdc8c4776 Author: John (J5) Palmieri johnp@redhat.com Date: Thu Apr 2 16:16:21 2009 -0400
add some nice little debugging tools
* moksha.debug and moksha.error js functions now take over for correctly checking if debug is enabled and outputting info. We should look into making these noops if debug is not enabled * connector middleware now accepts a _pp parameter and will output results in formatted by th epython pprint module
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py index 2ad1f52..4b5bbc2 100644 --- a/moksha/middleware/connector.py +++ b/moksha/middleware/connector.py @@ -22,10 +22,12 @@ import simplejson as json import urllib
from webob import Request, Response -from pylons import config, request +from pylons import config from pylons.i18n import ugettext
from moksha.exc import ApplicationNotFound, MokshaException +from pprint import pformat +
log = logging.getLogger(__name__)
@@ -103,13 +105,25 @@ class MokshaConnectorMiddleware(object): path = '/'.join(path) conn = self._connectors.get(conn)
+ # pretty print output + pretty_print = False + + if '_pp' in remote_params: + del remote_params['_pp'] + pretty_print = True + if conn: conn_obj = conn['connector_class'](environ, request) r = conn_obj._dispatch(op, path, remote_params, **dispatch_params) - if not isinstance(r, basestring): + + if pretty_print: + r = '<pre>' + pformat(r) + '</pre>' + elif not isinstance(r, basestring): r = json.dumps(r, separators=(',',':')) + if isinstance(r, unicode): r = r.encode('utf-8', 'replace') + response = Response(r) else: response = Response(status='404 Not Found') @@ -131,8 +145,11 @@ class MokshaConnectorMiddleware(object): 'path': conn_path, }
-def _get_connector(name): +def _get_connector(name, request=None): # TODO: having a connection pool might be nice c = MokshaConnectorMiddleware._connectors[name]
+ if not request: + from pylons import request + return c['connector_class'](request.environ, request) \ No newline at end of file diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js index 854caf8..4248a09 100644 --- a/moksha/public/javascript/moksha.js +++ b/moksha/public/javascript/moksha.js @@ -264,6 +264,21 @@ moksha = { }
return $.ajax(o); + }, + + debug: function(msg) { + if (typeof(moksha_debug) != 'undefined' && moksha_debug) { + // TODO: make this configurable (or perhaps just overriding this + // method is enough + + console.log(msg); + } + }, + + error: function(msg) { + // TODO: Make this do something to indicate it is different from a + // warning or info message + moksha.debug(msg); } }
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js index 0e276cf..d38ec9e 100644 --- a/moksha/public/javascript/ui/moksha.ui.grid.js +++ b/moksha/public/javascript/ui/moksha.ui.grid.js @@ -11,8 +11,7 @@ self.options.filters = $.secureEvalJSON(o.filters); } catch(e) { self.options.filters = {}; - if (moksha_debug) - console.log(e); + moksha.error(e); } }
moksha-commits@lists.fedorahosted.org