Ticket #2266: given_validators.diff
File given_validators.diff, 3.3 KB (added by , 18 years ago) |
---|
-
django/core/validators.py
258 258 for v in self.validator_list: 259 259 v(field_data, all_data) 260 260 261 class RequiredIfOtherField NotGiven(object):262 def __init__(self, other_field_name , error_message=gettext_lazy("Please enter something for at least one field.")):263 self.other, self.error_message = other_field_name , error_message261 class RequiredIfOtherFieldsNotGiven(object): 262 def __init__(self, other_field_names, error_message=gettext_lazy("Please enter something for at least one field.")): 263 self.other, self.error_message = other_field_names, error_message 264 264 self.always_test = True 265 265 266 266 def __call__(self, field_data, all_data): 267 if not all_data.get(self.other, False) and not field_data: 267 for field in self.other: 268 if all_data.get(field, False): 269 return 270 if not field_data: 268 271 raise ValidationError, self.error_message 269 272 273 class RequiredIfOtherFieldNotGiven(RequiredIfOtherFieldsNotGiven): 274 def __init__(self, other_field_name, error_message=gettext_lazy("Please enter something for at least one field.")): 275 RequiredIfOtherFieldsNotGiven.__init__(self, [other_field_name], error_message) 276 270 277 class RequiredIfOtherFieldsGiven(object): 271 278 def __init__(self, other_field_names, error_message=gettext_lazy("Please enter both fields or leave them both empty.")): 272 279 self.other, self.error_message = other_field_names, error_message 273 280 self.always_test = True 274 281 275 282 def __call__(self, field_data, all_data): 283 if field_data: 284 return 276 285 for field in self.other: 277 if all_data.get(field, False) and not field_data:286 if all_data.get(field, False): 278 287 raise ValidationError, self.error_message 279 288 280 289 class RequiredIfOtherFieldGiven(RequiredIfOtherFieldsGiven): -
docs/forms.txt
519 519 ``other_vaue``, then the validators in ``validator_list`` are all run 520 520 against the current field. 521 521 522 ``RequiredIfOtherFieldGiven`` 523 Takes the name of the other field and this field is only required if the 524 other field has a value. 525 526 ``RequiredIfOtherFieldsGiven`` 527 Similar to ``RequiredIfOtherFieldGiven``, except that it takes a list 528 of field names and if any one of the supplied fields has a value 529 provided, the field being validated is required. 530 522 531 ``RequiredIfOtherFieldNotGiven`` 523 532 Takes the name of the other field and this field is only required if the 524 533 other field has no value. 525 534 526 535 ``RequiredIfOtherFieldsNotGiven`` 527 536 Similar to ``RequiredIfOtherFieldNotGiven``, except that it takes a list 528 of field names and if any one of the supplied fields does not have a value529 provided,the field being validated is required.537 of field names and if none of the supplied fields has a value provided, 538 the field being validated is required. 530 539 531 540 ``RequiredIfOtherFieldEquals`` and ``RequiredIfOtherFieldDoesNotEqual`` 532 541 Each of these validator classes takes a field name and a value (in that