From 2b931f463d42c27999da79f760464b0fe61a58a4 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Mon, 5 Sep 2011 19:56:37 +0200 Subject: [PATCH] update djextdirect to v0.5. --- pyweb/djextdirect/__init__.py | 2 +- pyweb/djextdirect/formprovider.py | 6 +++--- pyweb/djextdirect/provider.py | 34 ++++++++++++++++++++++--------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pyweb/djextdirect/__init__.py b/pyweb/djextdirect/__init__.py index 169bb8d..61d0ce7 100644 --- a/pyweb/djextdirect/__init__.py +++ b/pyweb/djextdirect/__init__.py @@ -15,7 +15,7 @@ * GNU General Public License for more details. """ -VERSION = ( 0, 4 ) +VERSION = ( 0, 5 ) VERSIONSTR = "v%d.%d" % VERSION diff --git a/pyweb/djextdirect/formprovider.py b/pyweb/djextdirect/formprovider.py index 1e9fe82..7be0718 100644 --- a/pyweb/djextdirect/formprovider.py +++ b/pyweb/djextdirect/formprovider.py @@ -16,9 +16,10 @@ """ try: - import simplejson + import simplejson except ImportError: - import json as simplejson + import json as simplejson + import functools from django import forms @@ -270,7 +271,6 @@ class FormProvider(Provider): elif isinstance( field.widget, forms.Textarea ): extfld.update({ "xtype": "textarea", - "grow": True, }) elif isinstance( field.widget, forms.PasswordInput ): extfld.update({ diff --git a/pyweb/djextdirect/provider.py b/pyweb/djextdirect/provider.py index 9f4a841..673701e 100644 --- a/pyweb/djextdirect/provider.py +++ b/pyweb/djextdirect/provider.py @@ -112,8 +112,7 @@ class Provider( object ): method.EXT_flags = flags return method - def get_api( self, request ): - """ Introspect the methods and get a JSON description of this API. """ + def build_api_dict( self ): actdict = {} for clsname in self.classes: actdict[clsname] = [] @@ -125,10 +124,24 @@ class Provider( object ): methinfo.update( self.classes[clsname][methodname].EXT_flags ) actdict[clsname].append( methinfo ) + return actdict + + def get_api_plain( self, request ): + """ Introspect the methods and get a JSON description of only the API. """ + return HttpResponse( simplejson.dumps({ + "url": reverse( self.request ), + "type": "remoting", + "actions": self.build_api_dict() + }), mimetype="application/json" ) + + def get_api( self, request ): + """ Introspect the methods and get a javascript description of the API + that is meant to be embedded directly into the web site. + """ lines = ["%s = %s;" % ( self.name, simplejson.dumps({ "url": reverse( self.request ), "type": "remoting", - "actions": actdict + "actions": self.build_api_dict() }))] if self.autoadd: @@ -171,7 +184,7 @@ class Provider( object ): 'message': 'malformed request', 'where': unicode(err), "tid": None, # dunno - }), mimetype="text/javascript" ) + }), mimetype="application/json" ) else: return self.process_normal_request( request, rawjson ) else: @@ -267,9 +280,9 @@ class Provider( object ): }) if len(responses) == 1: - return HttpResponse( simplejson.dumps( responses[0] ), mimetype="text/javascript" ) + return HttpResponse( simplejson.dumps( responses[0] ), mimetype="application/json" ) else: - return HttpResponse( simplejson.dumps( responses ), mimetype="text/javascript" ) + return HttpResponse( simplejson.dumps( responses ), mimetype="application/json" ) def process_form_request( self, request, reqinfo ): """ Router for POST requests that submit form data and/or file uploads. """ @@ -325,16 +338,17 @@ class Provider( object ): if reqinfo['upload'] == "true": return HttpResponse( "" % simplejson.dumps(response), - mimetype="text/javascript" + mimetype="application/json" ) else: - return HttpResponse( simplejson.dumps( response ), mimetype="text/javascript" ) + return HttpResponse( simplejson.dumps( response ), mimetype="application/json" ) def get_urls(self): """ Return the URL patterns. """ pat = patterns('', - (r'api.js$', self.get_api ), - (r'router/?', self.request ), + (r'api.json$', self.get_api_plain ), + (r'api.js$', self.get_api ), + (r'router/?', self.request ), ) return pat