From ecbc1310eb19e098eceb8ad996d2c484e841735b Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sat, 24 Sep 2011 18:12:37 +0200 Subject: [PATCH] update djextdirect --- pyweb/djextdirect/formprovider.py | 4 ++-- pyweb/djextdirect/provider.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pyweb/djextdirect/formprovider.py b/pyweb/djextdirect/formprovider.py index 654321f..a255b91 100644 --- a/pyweb/djextdirect/formprovider.py +++ b/pyweb/djextdirect/formprovider.py @@ -292,8 +292,8 @@ class FormProvider(Provider): 'clsname': clsname, 'clslowername': formname, 'defaultconf': '{' - 'items:' + simplejson.dumps(items, indent=4) + ',' - 'fileUpload: ' + simplejson.dumps(hasfiles) + ',' + 'items:' + simplejson.dumps(items, cls=DjangoJSONEncoder, indent=4) + ',' + 'fileUpload: ' + simplejson.dumps(hasfiles, cls=DjangoJSONEncoder) + ',' '}', 'apiconf': ('{' 'load: ' + ("XD_%s.get" % clsname) + "," diff --git a/pyweb/djextdirect/provider.py b/pyweb/djextdirect/provider.py index 673701e..2766fb9 100644 --- a/pyweb/djextdirect/provider.py +++ b/pyweb/djextdirect/provider.py @@ -29,6 +29,8 @@ from django.conf import settings from django.conf.urls.defaults import patterns from django.core.urlresolvers import reverse from django.utils.datastructures import MultiValueDictKeyError +from django.core.serializers.json import DjangoJSONEncoder + def getname( cls_or_name ): """ If cls_or_name is not a string, return its __name__. """ @@ -132,17 +134,18 @@ class Provider( object ): "url": reverse( self.request ), "type": "remoting", "actions": self.build_api_dict() - }), mimetype="application/json" ) + }, cls=DjangoJSONEncoder), 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. """ + request.META["CSRF_COOKIE_USED"] = True lines = ["%s = %s;" % ( self.name, simplejson.dumps({ "url": reverse( self.request ), "type": "remoting", "actions": self.build_api_dict() - }))] + }, cls=DjangoJSONEncoder))] if self.autoadd: lines.append( @@ -162,6 +165,7 @@ class Provider( object ): It handles decoding requests, calling the appropriate function (if found) and encoding the response / exceptions. """ + request.META["CSRF_COOKIE_USED"] = True # First try to use request.POST, if that doesn't work check for req.raw_post_data. # The other way round this might make more sense because the case that uses # raw_post_data is way more common, but accessing request.POST after raw_post_data @@ -184,7 +188,7 @@ class Provider( object ): 'message': 'malformed request', 'where': unicode(err), "tid": None, # dunno - }), mimetype="application/json" ) + }, cls=DjangoJSONEncoder), mimetype="application/json" ) else: return self.process_normal_request( request, rawjson ) else: @@ -280,9 +284,9 @@ class Provider( object ): }) if len(responses) == 1: - return HttpResponse( simplejson.dumps( responses[0] ), mimetype="application/json" ) + return HttpResponse( simplejson.dumps( responses[0], cls=DjangoJSONEncoder ), mimetype="application/json" ) else: - return HttpResponse( simplejson.dumps( responses ), mimetype="application/json" ) + return HttpResponse( simplejson.dumps( responses, cls=DjangoJSONEncoder ), mimetype="application/json" ) def process_form_request( self, request, reqinfo ): """ Router for POST requests that submit form data and/or file uploads. """ @@ -337,11 +341,11 @@ class Provider( object ): if reqinfo['upload'] == "true": return HttpResponse( - "" % simplejson.dumps(response), + "" % simplejson.dumps(response, cls=DjangoJSONEncoder), mimetype="application/json" ) else: - return HttpResponse( simplejson.dumps( response ), mimetype="application/json" ) + return HttpResponse( simplejson.dumps( response, cls=DjangoJSONEncoder ), mimetype="application/json" ) def get_urls(self): """ Return the URL patterns. """