mirror of
https://github.com/django/django.git
synced 2025-07-07 11:19:12 +00:00
[soc2009/model-validation] Dont't validate already failed fields
This removes the duplicate messages we have been seeing git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10876 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e573fb41e9
commit
32916adca8
@ -16,7 +16,7 @@ FORM_TESTS = """
|
||||
>>> 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 @@ False
|
||||
>>> 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.
|
||||
|
||||
|
@ -606,13 +606,15 @@ class Model(object):
|
||||
"""
|
||||
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))
|
||||
|
@ -243,8 +243,7 @@ class BaseModelForm(BaseForm):
|
||||
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:
|
||||
|
@ -449,9 +449,9 @@ u'third-test'
|
||||
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):
|
||||
...
|
||||
|
Loading…
x
Reference in New Issue
Block a user