Improve validator for "percent" input widget
This commit is contained in:
parent
d693c00c47
commit
bd43884a1d
|
@ -79,7 +79,10 @@ class PercentInputWidget(dfwidget.TextInputWidget):
|
||||||
if pstruct is colander.null:
|
if pstruct is colander.null:
|
||||||
return colander.null
|
return colander.null
|
||||||
# convert "human-friendly" value to "traditional"
|
# convert "human-friendly" value to "traditional"
|
||||||
value = decimal.Decimal(pstruct)
|
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 = value.quantize(decimal.Decimal('0.00001'))
|
||||||
value /= 100
|
value /= 100
|
||||||
return six.text_type(value)
|
return six.text_type(value)
|
||||||
|
|
Loading…
Reference in a new issue