Permalink
Browse files

Fixed #266 -- Added ValidateIfOtherFieldEquals validator. Thanks agai…

…n, Hugo

git-svn-id: http://code.djangoproject.com/svn/django/trunk@405 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 63eecad commit 502755878d5d4d197793880945823dade7b90674 @adrianholovaty adrianholovaty committed Aug 4, 2005
Showing with 11 additions and 0 deletions.
  1. +11 −0 django/core/validators.py
View
11 django/core/validators.py
@@ -210,6 +210,17 @@ def __call__(self, field_data, all_data):
if field_data != all_data[self.other]:
raise ValidationError, self.error_message
+class ValidateIfOtherFieldEquals:
+ def __init__(self, other_field, other_value, validator_list):
+ self.other_field, self.other_value = other_field, other_value
+ self.validator_list = validator_list
+ self.always_test = True
+
+ def __call__(self, field_data, all_data):
+ if all_data.has_key(self.other_field) and all_data[self.other_field] == self.other_value:
+ for v in self.validator_list:
+ v(field_data, all_data)
+
class RequiredIfOtherFieldNotGiven:
def __init__(self, other_field_name, error_message="Please enter something for at least one field."):
self.other, self.error_message = other_field_name, error_message

0 comments on commit 5027558

Please sign in to comment.