1. Luke Plant
  2. lukeplant_python

Commits

Luke Plant  committed 2f5128e

- Added VALIDATOR_APP_IGNORE_PATHS setting
- Added support for mod_python handler (thanks nesh@studioquattro.co.yu)

  • Participants
  • Parent commits 64866b9
  • Branches default

Comments (0)

Files changed (1)

File django/apps/validator/models/validator.py

View file
     def _module_do_validation(request, response):
         """Do validation on response and log if it fails."""
         from django.conf.settings import VALIDATOR_APP_VALIDATORS
+        try:
+            from django.conf.settings import VALIDATOR_APP_IGNORE_PATHS
+        except ImportError:
+            VALIDATOR_APP_IGNORE_PATHS = ()
+            
+        
         import tempfile
         import cPickle
         import os
         except KeyError, IndexError:
             # no content type, or no validator for that content type
             return
+            
+        for ignore_path in VALIDATOR_APP_IGNORE_PATHS:
+            if request.path.startswith(ignore_path):
+                return
         
         # first store data in temporary file
         (tmpfilehandle, tmpfilepath) = tempfile.mkstemp()
         os.unlink(tmpfilepath)
         
         if len(errors) > 0:
-            failure = ValidationFailure(path = request.path)
+            failure = ValidationFailure(errors = errors)
+            failure.path = request.path
+            qs = request.META.get('QUERY_STRING','')
+            if len(qs) > 0:
+                failure.path += '?' + qs
             failure.errors = errors
-            req = copy.deepcopy(request)
-            # remove the stuff we can't serialize
-            req.META['wsgi.errors'] = None
-            req.META['wsgi.file_wrapper'] = None
-            req.META['wsgi.input'] = None
+
+            from django.core.handlers.modpython import ModPythonRequest
+            
+            if isinstance(request, ModPythonRequest):
+                # prepopulate vars
+                request._get_get()
+                request._get_post()
+                request._get_cookies()
+                request._get_files()
+                request._get_meta()
+                request._get_request()
+                request._get_raw_post_data()
+                request._get_user()
+                mp = request._req
+                del request._req # get rid of mp_request
+                req = copy.deepcopy(request)
+                request._req = mp # restore mp_request
+            else:
+                req = copy.deepcopy(request)
+                # remove the stuff we can't serialize
+                del req.META['wsgi.errors']
+                del req.META['wsgi.file_wrapper']
+                del req.META['wsgi.input']
             
             failure.request = cPickle.dumps(req)
             failure.response = cPickle.dumps(response)