Commits

seppo0010simpler committed a528493

Support Backbone.emulateHTTP

  • Participants
  • Parent commits fa05099

Comments (0)

Files changed (1)

File piston/resource.py

 
     def form_validation_response(self, e):
         """
-        Method to return form validation error information. 
+        Method to return form validation error information.
         You will probably want to override this in your own
         `Resource` subclass.
         """
         """
         rm = request.method.upper()
 
+        if 'HTTP_X_HTTP_METHOD_OVERRIDE' in request.META:
+            rm = request.META['HTTP_X_HTTP_METHOD_OVERRIDE']
+
         # Django's internal mechanism doesn't pick up
         # PUT request, so we trick it a little here.
         if rm == "PUT":
             except MimerDataException:
                 return rc.BAD_REQUEST
             if not hasattr(request, 'data'):
-                if rm == 'POST':
+                if rm == 'POST' or ('HTTP_X_HTTP_METHOD_OVERRIDE' in
+                        request.META):
                     request.data = request.POST
                 elif rm == 'PUT':
                     request.data = request.PUT
         status_code = 200
 
         # If we're looking at a response object which contains non-string
-        # content, then assume we should use the emitter to format that 
+        # content, then assume we should use the emitter to format that
         # content
         if self._use_emitter(result):
             status_code = result.status_code
 
     def error_handler(self, e, request, meth, em_format):
         """
-        Override this method to add handling of errors customized for your 
+        Override this method to add handling of errors customized for your
         needs
         """
         if isinstance(e, FormValidationError):
 
         elif isinstance(e, HttpStatusCode):
             return e.response
- 
-        else: 
+
+        else:
             """
             On errors (like code errors), we'd like to be able to
             give crash reports to both admins and also the calling