]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/widgets/__init__.py
Correct conversion of UserSelect field
[bluechips.git] / bluechips / widgets / __init__.py
index 43dbea99cfe5230f21aa1f7f0da7d874866e32cb..8c25e78c37af0f2794228388d0487317af341fd0 100644 (file)
@@ -5,6 +5,8 @@ from tw.forms import validators
 from bluechips import model
 from bluechips.model import meta
 
+from decimal import Decimal
+
 class UserSelect(forms.SingleSelectField):
     @staticmethod
     def getUserList():
@@ -13,13 +15,18 @@ class UserSelect(forms.SingleSelectField):
     
     options = getUserList
     validator = validators.Wrapper(
-        to_python=meta.Session.query(model.User).get,
-        from_python=(lambda x: x.id))
+        to_python=(lambda x: meta.Session.query(model.User).get(int(x))),
+        from_python=(lambda x: str(x.id)))
+    
+    def _is_option_selected(self, option_value, value):
+        return option_value == value.id
 
 class AmountField(forms.TextField):
     size = 8
     validator = validators.All(
-        validators.Number(),
+        validators.Wrapper(
+            to_python=Decimal,
+            from_python=str),
         validators.Regex(r'^[0-9]*(\.[0-9]{2})?$', not_empty=True))
 
 __all__ = ['UserSelect', 'AmountField']