Improve validator for "percent" input widget

This commit is contained in:
Lance Edgar 2019-02-13 15:15:47 -06:00
parent d693c00c47
commit bd43884a1d

View file

@ -79,7 +79,10 @@ class PercentInputWidget(dfwidget.TextInputWidget):
if pstruct is colander.null:
return colander.null
# convert "human-friendly" value to "traditional"
try:
value = decimal.Decimal(pstruct)
except decimal.InvalidOperation:
raise colander.Invalid(field.schema, "Invalid decimal string: {}".format(pstruct))
value = value.quantize(decimal.Decimal('0.00001'))
value /= 100
return six.text_type(value)