Browse Source

update djextdirect to v0.5.

Natenom/support-murmur-13-1446181288462
Michael Ziegler 14 years ago
parent
commit
2b931f463d
  1. 2
      pyweb/djextdirect/__init__.py
  2. 2
      pyweb/djextdirect/formprovider.py
  3. 30
      pyweb/djextdirect/provider.py

2
pyweb/djextdirect/__init__.py

@ -15,7 +15,7 @@
* GNU General Public License for more details. * GNU General Public License for more details.
""" """
VERSION = ( 0, 4 )
VERSION = ( 0, 5 )
VERSIONSTR = "v%d.%d" % VERSION VERSIONSTR = "v%d.%d" % VERSION

2
pyweb/djextdirect/formprovider.py

@ -19,6 +19,7 @@ try:
import simplejson import simplejson
except ImportError: except ImportError:
import json as simplejson import json as simplejson
import functools import functools
from django import forms from django import forms
@ -270,7 +271,6 @@ class FormProvider(Provider):
elif isinstance( field.widget, forms.Textarea ): elif isinstance( field.widget, forms.Textarea ):
extfld.update({ extfld.update({
"xtype": "textarea", "xtype": "textarea",
"grow": True,
}) })
elif isinstance( field.widget, forms.PasswordInput ): elif isinstance( field.widget, forms.PasswordInput ):
extfld.update({ extfld.update({

30
pyweb/djextdirect/provider.py

@ -112,8 +112,7 @@ class Provider( object ):
method.EXT_flags = flags method.EXT_flags = flags
return method return method
def get_api( self, request ):
""" Introspect the methods and get a JSON description of this API. """
def build_api_dict( self ):
actdict = {} actdict = {}
for clsname in self.classes: for clsname in self.classes:
actdict[clsname] = [] actdict[clsname] = []
@ -125,10 +124,24 @@ class Provider( object ):
methinfo.update( self.classes[clsname][methodname].EXT_flags ) methinfo.update( self.classes[clsname][methodname].EXT_flags )
actdict[clsname].append( methinfo ) 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({ lines = ["%s = %s;" % ( self.name, simplejson.dumps({
"url": reverse( self.request ), "url": reverse( self.request ),
"type": "remoting", "type": "remoting",
"actions": actdict
"actions": self.build_api_dict()
}))] }))]
if self.autoadd: if self.autoadd:
@ -171,7 +184,7 @@ class Provider( object ):
'message': 'malformed request', 'message': 'malformed request',
'where': unicode(err), 'where': unicode(err),
"tid": None, # dunno "tid": None, # dunno
}), mimetype="text/javascript" )
}), mimetype="application/json" )
else: else:
return self.process_normal_request( request, rawjson ) return self.process_normal_request( request, rawjson )
else: else:
@ -267,9 +280,9 @@ class Provider( object ):
}) })
if len(responses) == 1: if len(responses) == 1:
return HttpResponse( simplejson.dumps( responses[0] ), mimetype="text/javascript" )
return HttpResponse( simplejson.dumps( responses[0] ), mimetype="application/json" )
else: else:
return HttpResponse( simplejson.dumps( responses ), mimetype="text/javascript" )
return HttpResponse( simplejson.dumps( responses ), mimetype="application/json" )
def process_form_request( self, request, reqinfo ): def process_form_request( self, request, reqinfo ):
""" Router for POST requests that submit form data and/or file uploads. """ """ Router for POST requests that submit form data and/or file uploads. """
@ -325,14 +338,15 @@ class Provider( object ):
if reqinfo['upload'] == "true": if reqinfo['upload'] == "true":
return HttpResponse( return HttpResponse(
"<html><body><textarea>%s</textarea></body></html>" % simplejson.dumps(response), "<html><body><textarea>%s</textarea></body></html>" % simplejson.dumps(response),
mimetype="text/javascript"
mimetype="application/json"
) )
else: else:
return HttpResponse( simplejson.dumps( response ), mimetype="text/javascript" )
return HttpResponse( simplejson.dumps( response ), mimetype="application/json" )
def get_urls(self): def get_urls(self):
""" Return the URL patterns. """ """ Return the URL patterns. """
pat = patterns('', pat = patterns('',
(r'api.json$', self.get_api_plain ),
(r'api.js$', self.get_api ), (r'api.js$', self.get_api ),
(r'router/?', self.request ), (r'router/?', self.request ),
) )

Loading…
Cancel
Save