diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-08-04 15:12:11 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-08-04 15:12:11 +0000 |
| commit | 502755878d5d4d197793880945823dade7b90674 (patch) | |
| tree | 984b31323c1b21591ed91036b94ee4fe4ea0a942 | |
| parent | 63eecadfc66a1b52abda9921598750ea27095456 (diff) | |
Fixed #266 -- Added ValidateIfOtherFieldEquals validator. Thanks again, Hugo
git-svn-id: http://code.djangoproject.com/svn/django/trunk@405 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/validators.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/django/core/validators.py b/django/core/validators.py index 9cd6ddad30..b5ec72e487 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -210,6 +210,17 @@ class AlwaysMatchesOtherField: 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 |
