Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 502755878d5d4d197793880945823dade7b90674 1 parent 63eecad
Adrian Holovaty authored August 04, 2005

Showing 1 changed file with 11 additions and 0 deletions. Show diff stats Hide diff stats

  1. 11  django/core/validators.py
11  django/core/validators.py
@@ -210,6 +210,17 @@ def __call__(self, field_data, all_data):
210 210
         if field_data != all_data[self.other]:
211 211
             raise ValidationError, self.error_message
212 212
 
  213
+class ValidateIfOtherFieldEquals:
  214
+    def __init__(self, other_field, other_value, validator_list):
  215
+        self.other_field, self.other_value = other_field, other_value
  216
+        self.validator_list = validator_list
  217
+        self.always_test = True
  218
+
  219
+    def __call__(self, field_data, all_data):
  220
+        if all_data.has_key(self.other_field) and all_data[self.other_field] == self.other_value:
  221
+            for v in self.validator_list:
  222
+                v(field_data, all_data)
  223
+
213 224
 class RequiredIfOtherFieldNotGiven:
214 225
     def __init__(self, other_field_name, error_message="Please enter something for at least one field."):
215 226
         self.other, self.error_message = other_field_name, error_message

0 notes on commit 5027558

Please sign in to comment.
Something went wrong with that request. Please try again.