]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/widgets/__init__.py
Switch from using Decimal to using a new Currency class
[bluechips.git] / bluechips / widgets / __init__.py
index 3509ee2cf478a83080dcdfe103c1299e5560d0b3..545b88e8a217302ee7d6153248b24ae6adefaa10 100644 (file)
@@ -5,7 +5,7 @@ from tw.forms import validators
 from bluechips import model
 from bluechips.model import meta
 
-from decimal import Decimal
+from bluechips.model.types import Currency
 
 class UserSelect(forms.SingleSelectField):
     @staticmethod
@@ -28,9 +28,9 @@ class AmountField(forms.TextField):
     size = 8
     validator = validators.All(
         validators.Wrapper(
-            to_python=Decimal,
-            from_python=str),
-        validators.Regex(r'^[0-9]*(\.[0-9]{2})?$', not_empty=True))
+            to_python=(lambda x: Currency(float(x) * 100)),
+            from_python=Currency.__str_no_dollar__),
+        validators.Regex(r'^[0-9]*(\.[0-9]{2})?$'))
 
 # This is virtually copied from formencode.validator.FieldsMatch, but
 # I wanted my own version for fields that shouldn't match