Author: Honza_Kral
Date: 2009-06-01 10:41:41 -0500 (Mon, 01 Jun 2009)
New Revision: 10876

Modified:
   django/branches/soc2009/model-validation/django/contrib/auth/tests/forms.py
   django/branches/soc2009/model-validation/django/db/models/base.py
   django/branches/soc2009/model-validation/django/forms/models.py
   
django/branches/soc2009/model-validation/tests/modeltests/model_forms/models.py
Log:
[soc2009/model-validation] Dont't validate already failed fields

This removes the duplicate messages we have been seeing

Modified: 
django/branches/soc2009/model-validation/django/contrib/auth/tests/forms.py
===================================================================
--- django/branches/soc2009/model-validation/django/contrib/auth/tests/forms.py 
2009-06-01 15:41:15 UTC (rev 10875)
+++ django/branches/soc2009/model-validation/django/contrib/auth/tests/forms.py 
2009-06-01 15:41:41 UTC (rev 10876)
@@ -16,7 +16,7 @@
 >>> form.is_valid()
 False
 >>> form["username"].errors
-[u'A user with that username already exists.', u'This field cannot be blank.']
+[u'A user with that username already exists.']
 
 # The username contains invalid data.
 
@@ -29,7 +29,7 @@
 >>> form.is_valid()
 False
 >>> form["username"].errors
-[u'This value must contain only letters, numbers and underscores.', u'This 
field cannot be blank.']
+[u'This value must contain only letters, numbers and underscores.']
 
 # The verification password is incorrect.
 

Modified: django/branches/soc2009/model-validation/django/db/models/base.py
===================================================================
--- django/branches/soc2009/model-validation/django/db/models/base.py   
2009-06-01 15:41:15 UTC (rev 10875)
+++ django/branches/soc2009/model-validation/django/db/models/base.py   
2009-06-01 15:41:41 UTC (rev 10876)
@@ -606,13 +606,15 @@
         """
         pass
 
-    def clean(self):
+    def clean(self, exclude=[]):
         """
         Cleans all fields and raises ValidationError containing message_dict 
of 
         all validation errors if any occur.
         """
         errors = {}
         for f in self._meta.fields:
+            if f.name in exclude:
+                continue
             try:
                 # TODO: is the [sg]etattr correct?
                 setattr(self, f.attname, f.clean(getattr(self, f.attname), 
self))

Modified: django/branches/soc2009/model-validation/django/forms/models.py
===================================================================
--- django/branches/soc2009/model-validation/django/forms/models.py     
2009-06-01 15:41:15 UTC (rev 10875)
+++ django/branches/soc2009/model-validation/django/forms/models.py     
2009-06-01 15:41:41 UTC (rev 10876)
@@ -243,8 +243,7 @@
         self.instance = make_instance(self, self.instance, opts.fields, 
opts.exclude)
         self.validate_unique()
         try:
-            # FIMXE: what to do about duplicate errors? (is required etc.)
-            self.instance.clean()
+            self.instance.clean(exclude=self._errors.keys())
         except ValidationError, e:
             for k, v in e.message_dict.items():
                 if k != NON_FIELD_ERRORS:

Modified: 
django/branches/soc2009/model-validation/tests/modeltests/model_forms/models.py
===================================================================
--- 
django/branches/soc2009/model-validation/tests/modeltests/model_forms/models.py 
    2009-06-01 15:41:15 UTC (rev 10875)
+++ 
django/branches/soc2009/model-validation/tests/modeltests/model_forms/models.py 
    2009-06-01 15:41:41 UTC (rev 10876)
@@ -449,9 +449,9 @@
 If you call save() with invalid data, you'll get a ValueError.
 >>> f = CategoryForm({'name': '', 'slug': 'not a slug!', 'url': 'foo'})
 >>> f.errors['name']
-[u'This field is required.', u'This field cannot be blank.']
+[u'This field is required.']
 >>> f.errors['slug']
-[u"Enter a valid 'slug' consisting of letters, numbers, underscores or 
hyphens.", u'This field cannot be blank.']
+[u"Enter a valid 'slug' consisting of letters, numbers, underscores or 
hyphens."]
 >>> f.cleaned_data
 Traceback (most recent call last):
 ...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to