From bd43884a1d6cec2ec0a297ffa055b0c3d65006fa Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 13 Feb 2019 15:15:47 -0600 Subject: [PATCH] Improve validator for "percent" input widget --- tailbone/forms/widgets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tailbone/forms/widgets.py b/tailbone/forms/widgets.py index 7c89fa7d..b90f9dda 100644 --- a/tailbone/forms/widgets.py +++ b/tailbone/forms/widgets.py @@ -79,7 +79,10 @@ class PercentInputWidget(dfwidget.TextInputWidget): if pstruct is colander.null: return colander.null # 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 /= 100 return six.text_type(value)