X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=bluechips%2Fwidgets%2F__init__.py;h=6e8ec966ce71d2e029d554d0f9bd9b865ac9ea62;hb=9458527642fab328a945d06daed04404c1ae2091;hp=9da303d68945c5bcc028b140d8ec49a426651e81;hpb=376192728a6625831c11d4c9d192f0a48b7ca417;p=bluechips.git diff --git a/bluechips/widgets/__init__.py b/bluechips/widgets/__init__.py index 9da303d..6e8ec96 100644 --- a/bluechips/widgets/__init__.py +++ b/bluechips/widgets/__init__.py @@ -5,9 +5,7 @@ from tw.forms import validators from bluechips import model from bluechips.model import meta -from bluechips.lib.base import _ - -from decimal import Decimal +from bluechips.model.types import Currency class UserSelect(forms.SingleSelectField): @staticmethod @@ -30,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 @@ -47,7 +45,7 @@ class FieldsDontMatch(validators.FormValidator): __unpackargs__ = ('*', 'field_names') messages = { - 'invalid': _("Fields match") + 'invalid': "Fields match" } def validate_partial(self, field_dict, state):