Ticket #2014: required-if-other_label-insteadof-value_with-docs.diff
File required-if-other_label-insteadof-value_with-docs.diff, 2.4 KB (added by , 18 years ago) |
---|
-
docs/forms.txt
570 570 order). If the given field does (or does not have, in the latter case) the 571 571 given value, then the current field being validated is required. 572 572 573 An optional third argument can be passed which, if given, is used 574 in error messages instead of the value. This allows more user friendly 575 error messages if the value itself is not descriptive enough. 576 573 577 Note that because validators are called before any ``do_html2python()`` 574 578 functions, the value being compared against is a string. So 575 579 ``RequiredIfOtherFieldEquals('choice', '1')`` is correct, whilst -
django/core/validators.py
283 283 RequiredIfOtherFieldsGiven.__init__(self, [other_field_name], error_message) 284 284 285 285 class RequiredIfOtherFieldEquals(object): 286 def __init__(self, other_field, other_value, error_message=None):286 def __init__(self, other_field, other_value, other_label=None, error_message=None): 287 287 self.other_field = other_field 288 288 self.other_value = other_value 289 other_label = other_label or other_value 289 290 self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is %(value)s"), { 290 'field': other_field, 'value': other_ value})291 'field': other_field, 'value': other_label}) 291 292 self.always_test = True 292 293 293 294 def __call__(self, field_data, all_data): … … 295 296 raise ValidationError(self.error_message) 296 297 297 298 class RequiredIfOtherFieldDoesNotEqual(object): 298 def __init__(self, other_field, other_value, error_message=None):299 def __init__(self, other_field, other_value, other_label=None, error_message=None): 299 300 self.other_field = other_field 300 301 self.other_value = other_value 302 other_label = other_label or other_value 301 303 self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is not %(value)s"), { 302 'field': other_field, 'value': other_ value})304 'field': other_field, 'value': other_label}) 303 305 self.always_test = True 304 306 305 307 def __call__(self, field_data, all_data):