Author: Honza_Kral
Date: 2009-06-02 21:38:39 -0500 (Tue, 02 Jun 2009)
New Revision: 10909
Modified:
django/branches/soc2009/model-validation/django/forms/fields.py
django/branches/soc2009/model-validation/django/forms/forms.py
Log:
[soc2009/model-validation] Added code for calling validators on form fields
Modified: django/branches/soc2009/model-validation/django/forms/fields.py
===================================================================
--- django/branches/soc2009/model-validation/django/forms/fields.py
2009-06-03 02:38:23 UTC (rev 10908)
+++ django/branches/soc2009/model-validation/django/forms/fields.py
2009-06-03 02:38:39 UTC (rev 10909)
@@ -180,7 +180,6 @@
return {'maxlength': str(self.max_length)}
class IntegerField(Field):
- default_validators = [validators.validate_integer]
default_error_messages = {
'invalid': _(u'Enter a whole number.'),
'max_value': _(u'Ensure this value is less than or equal to %s.'),
Modified: django/branches/soc2009/model-validation/django/forms/forms.py
===================================================================
--- django/branches/soc2009/model-validation/django/forms/forms.py
2009-06-03 02:38:23 UTC (rev 10908)
+++ django/branches/soc2009/model-validation/django/forms/forms.py
2009-06-03 02:38:39 UTC (rev 10909)
@@ -247,6 +247,20 @@
self._errors[name] = self.error_class(e.messages)
if name in self.cleaned_data:
del self.cleaned_data[name]
+
+ # run all the validators after the fields have been cleaned since they
+ # need access to all_values
+ for name, field in self.fields.items():
+ if not name in self.cleaned_data:
+ continue
+ for v in field.validators:
+ try:
+ v(self.cleaned_data[name], all_values=self.cleaned_data)
+ except ValidationError, e:
+ self._errors.setdefault(name,
self.error_class()).extend(e.messages)
+ if name in self.cleaned_data:
+ del self.cleaned_data[name]
+
try:
self.cleaned_data = self.clean()
except ValidationError, e:
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---