Using standard assert instead of self.fail().

This commit is contained in:
Trang Tran 2017-10-26 21:17:49 +07:00 committed by Carlton Gibson
parent 0419a23fb8
commit 831f688cc5

View File

@ -992,8 +992,7 @@ class DecimalField(Field):
'max_digits': _('Ensure that there are no more than {max_digits} digits in total.'),
'max_decimal_places': _('Ensure that there are no more than {max_decimal_places} decimal places.'),
'max_whole_digits': _('Ensure that there are no more than {max_whole_digits} digits before the decimal point.'),
'max_string_length': _('String value too large.'),
'invalid_rounding': _('Invalid rounding option {rounding}. Valid values for rounding are: {valid_roundings}')
'max_string_length': _('String value too large.')
}
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
@ -1030,9 +1029,10 @@ class DecimalField(Field):
self.validators.append(
MinValueValidator(self.min_value, message=message))
if rounding is not None:
valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')]
if rounding is not None and rounding not in valid_roundings:
self.fail('invalid_rounding', rounding=rounding, valid_roundings=valid_roundings)
assert rounding in valid_roundings, \
'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings)
self.rounding = rounding
def to_internal_value(self, data):