Commits

Luke Plant committed 8a0d6cf

Updated for magic-removal, and some other fixes

Comments (0)

Files changed (4)

django/apps/validator/models.py

 from django.db import models
+from django.contrib.auth.models import User
 
 class ValidationFailure(models.Model):
     timestamp = models.DateTimeField("Time", default=models.LazyDate())
             return cPickle.loads(self.response)
         except EOFError, UnpicklingError:
             return None
-
-        
-    def _pre_save(self):
-        # debug - allow admin interface
-        if self.response is None:
-            self.response = ''
-        if self.request is None:
-            self.request = ''
-
+  
     class Meta:
         ordering = ('-timestamp',)
-        
+  
     class Admin:
         fields =  (
             (None, {'fields': ('timestamp', 'path', 'method', 'errors')}),
         )
-    
-    
+
+      
     def do_validation(request, response):
         """Do validation on response and log if it fails."""
         from django.conf import settings
             VALIDATOR_APP_IGNORE_PATHS = settings.VALIDATOR_APP_IGNORE_PATHS
         except Attribute:
             VALIDATOR_APP_IGNORE_PATHS = ()
-            
-        
+                  
         import tempfile
         import cPickle
         import os
         if len(errors) > 0:
             failure = ValidationFailure(errors=errors)
             failure.path = request.path
-            qs = request.models.get('QUERY_STRING','')
+            qs = request.META.get('QUERY_STRING','')
             if len(qs) > 0:
                 failure.path += '?' + qs
             failure.errors = errors
                 request._get_user()
                 mp = request._req
                 del request._req # get rid of mp_request
-                req = copy.deepcopy(request)
+                try:
+                    req = copy.deepcopy(request)
+                except Exception, e:
+                    req = "Couldn't stash a copy of the request: %s" % str(e)
                 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']
+                try:
+                    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']
+                except Exception, e:
+                    # TODO - work out why this happens
+                    req = "Couldn't stash a copy of the request: %s" % str(e)
             
             failure.request = cPickle.dumps(req)
             failure.response = cPickle.dumps(response)

django/apps/validator/urls.py

 from lukeplant_me_uk.django.apps.validator.models import ValidationFailure
 
 info_dict = {
-    'model': ValidationFailure,
+    'queryset': ValidationFailure.objects.all(),
 }
 
 urlpatterns = patterns('',
     (r'^$', 
         'django.views.generic.list_detail.object_list', 
-        dict(info_dict, allow_empty=True) ),
+        dict(info_dict, allow_empty=True)),
     (r'^(?P<object_id>\d+)/$', 
         'django.views.generic.list_detail.object_detail',
         info_dict),

django/apps/validator/views.py

     if request.POST:
         postkeys = request.POST.keys()
         if 'deleteall' in postkeys:
-            for vf in ValidationFailure.objects.get_list():
-                vf.delete()
+            ValidationFailure.objects.all().delete()
         elif 'deleteselected' in postkeys:
             for k in postkeys:
                 if k.startswith('deleteitem'):
                     k = k[len('deleteitem'):]
                     try:
-                        vf = ValidationFailure.get_object(id__exact=k)
+                        vf = ValidationFailure.objects.get(id=k)
                         vf.delete()
                     except ValidationFailure.DoesNotExist:
                         pass
 def delete(request, object_id):
     if request.POST:
         try:
-            vf = validationfailures.get_object(id__exact=object_id)
+            vf = ValidationFailure.objects.get(id=object_id)
             vf.delete()
         except ValidationFailure.DoesNotExist:
             pass

django_validator.e3p

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE Project SYSTEM "Project-3.7.dtd">
 <!-- Project file for project django_validator -->
-<!-- Saved: 2005-12-03, 16:28:42 -->
-<!-- Copyright (C) 2005 ,  -->
+<!-- Saved: 2006-01-25, 01:09:05 -->
+<!-- Copyright (C) 2006 ,  -->
 <Project version="3.7">
   <ProgLanguage mixed="0">Python</ProgLanguage>
   <UIType>Qt</UIType>
       <Dir>django</Dir>
       <Dir>apps</Dir>
       <Dir>validator</Dir>
-      <Dir>models</Dir>
-      <Name>validator.py</Name>
-    </Source>
-    <Source>
-      <Dir>django</Dir>
-      <Dir>apps</Dir>
-      <Dir>validator</Dir>
-      <Dir>models</Dir>
-      <Name>__init__.py</Name>
-    </Source>
-    <Source>
-      <Dir>django</Dir>
-      <Dir>apps</Dir>
-      <Dir>validator</Dir>
       <Name>urls.py</Name>
     </Source>
     <Source>
     <Source>
       <Name>__init__.py</Name>
     </Source>
+    <Source>
+      <Dir>django</Dir>
+      <Dir>apps</Dir>
+      <Dir>validator</Dir>
+      <Name>models.py</Name>
+    </Source>
   </Sources>
   <Forms>
   </Forms>