From: Joseph Spiros Date: Thu, 26 Aug 2010 10:42:46 +0000 (-0400) Subject: Adding support for multiple simultaneous Ext.Direct calls packed into an array. X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/e47a299b1e562a3e6e16cc3c726b84a5a8f542ef Adding support for multiple simultaneous Ext.Direct calls packed into an array. --- diff --git a/contrib/gilbert/sites.py b/contrib/gilbert/sites.py index 064666b..8f666f9 100644 --- a/contrib/gilbert/sites.py +++ b/contrib/gilbert/sites.py @@ -201,10 +201,25 @@ class GilbertSite(object): 'upload': request.POST.get('extUpload', False), 'data': None, } + response = self.handle_ext_request(request, ext_request, app_label) else: - ext_request = json.loads(request.raw_post_data) - ext_request['upload'] = False + ext_requests = json.loads(request.raw_post_data) + if type(ext_requests) is dict: + ext_requests['upload'] = False + response = self.handle_ext_request(request, ext_requests, app_label) + else: + responses = [] + for ext_request in ext_requests: + ext_request['upload'] = False + responses.append(self.handle_ext_request(request, ext_request, app_label)) + response = responses + if submitted_form: + if ext_request['upload'] is True: + return HttpResponse(('' % json.dumps(response))) + return HttpResponse(json.dumps(response), content_type=('application/json; charset=%s' % settings.DEFAULT_CHARSET)) + + def handle_ext_request(self, request, ext_request, app_label=None): try: plugin = None @@ -224,14 +239,10 @@ class GilbertSite(object): if method is None or (method.restricted and not self.has_permission(request)): raise NotImplementedError('The method named \'%s\' is not available' % method.name) - response = {'type': 'rpc', 'tid': ext_request['tid'], 'action': ext_request['action'], 'method': ext_request['method'], 'result': method(request, *(ext_request['data'] or []))} + return {'type': 'rpc', 'tid': ext_request['tid'], 'action': ext_request['action'], 'method': ext_request['method'], 'result': method(request, *(ext_request['data'] or []))} except: exc_type, exc_value, exc_traceback = sys.exc_info() - response = {'type': 'exception', 'tid': ext_request['tid'], 'message': ('%s: %s' % (exc_type, exc_value)), 'where': format_tb(exc_traceback)[0]} - - if submitted_form and ext_request['upload'] is True: - return HttpResponse(('' % json.dumps(response))) - return HttpResponse(json.dumps(response), content_type=('application/json; charset=%s' % settings.DEFAULT_CHARSET)) + return {'type': 'exception', 'tid': ext_request['tid'], 'message': ('%s: %s' % (exc_type, exc_value)), 'where': format_tb(exc_traceback)[0]} site = GilbertSite() \ No newline at end of file