From f1f2e846bb8a5ac9c803b6740a8fc8ff19cc1eb5 Mon Sep 17 00:00:00 2001 From: Scott Torborg Date: Thu, 5 Nov 2009 17:45:45 -1000 Subject: [PATCH] don't enter a non-zero currency amount --- bluechips/model/types.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bluechips/model/types.py b/bluechips/model/types.py index fdd3b8b..5423de9 100644 --- a/bluechips/model/types.py +++ b/bluechips/model/types.py @@ -38,7 +38,8 @@ locale.localeconv = localeconv class CurrencyValidator(validators.FancyValidator): "A validator to convert to Currency objects." messages = {'amount': "Please enter a valid currency amount", - 'precision': "Only two digits after the decimal, please"} + 'precision': "Only two digits after the decimal, please", + 'nonzero': "Please enter a non-zero amount"} def _to_python(self, value, state): try: @@ -48,7 +49,10 @@ class CurrencyValidator(validators.FancyValidator): value, state) else: ret = dec.quantize(Decimal('1.00')) - if ret != dec: + if ret == 0: + raise Invalid(self.message('nonzero', state), + value, state) + elif ret != dec: raise Invalid(self.message('precision', state), value, state) else: -- 2.45.2