Ticket #2014: required-if-other_label-insteadof-value.patch
File required-if-other_label-insteadof-value.patch, 2.0 KB (added by , 18 years ago) |
---|
-
django/core/validators.py
276 276 RequiredIfOtherFieldsGiven.__init__(self, [other_field_name], error_message) 277 277 278 278 class RequiredIfOtherFieldEquals: 279 def __init__(self, other_field, other_value, error_message=None):279 def __init__(self, other_field, other_value, other_label=None, error_message=None): 280 280 self.other_field = other_field 281 281 self.other_value = other_value 282 self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is %(value)s"), { 283 'field': other_field, 'value': other_value}) 282 if other_label is None: 283 other_label = other_value 284 self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is %(label)s"), { 285 'field': other_field, 'label': other_label}) 284 286 self.always_test = True 285 287 286 288 def __call__(self, field_data, all_data): … … 288 290 raise ValidationError(self.error_message) 289 291 290 292 class RequiredIfOtherFieldDoesNotEqual: 291 def __init__(self, other_field, other_value, error_message=None):293 def __init__(self, other_field, other_value, other_label=None, error_message=None): 292 294 self.other_field = other_field 293 295 self.other_value = other_value 294 self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is not %(value)s"), { 295 'field': other_field, 'value': other_value}) 296 if other_label is None: 297 other_label = other_value 298 self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is not %(label)s"), { 299 'field': other_field, 'label': other_label}) 296 300 self.always_test = True 297 301 298 302 def __call__(self, field_data, all_data):