]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/widgets/__init__.py
Solve a multithreading issue with the UserSelect converter
[bluechips.git] / bluechips / widgets / __init__.py
1 from tw import forms
2
3 from tw.forms import validators
4
5 from bluechips import model
6 from bluechips.model import meta
7
8 from decimal import Decimal
9
10 class UserSelect(forms.SingleSelectField):
11     @staticmethod
12     def getUserList():
13         for u in meta.Session.query(model.User):
14             yield (u.id, u.name)
15     
16     options = getUserList
17     validator = validators.Wrapper(
18         to_python=(lambda x: meta.Session.query(model.User).get(x)),
19         from_python=(lambda x: x.id))
20
21 class AmountField(forms.TextField):
22     size = 8
23     validator = validators.All(
24         validators.Wrapper(
25             to_python=Decimal,
26             from_python=str),
27         validators.Regex(r'^[0-9]*(\.[0-9]{2})?$', not_empty=True))
28
29 __all__ = ['UserSelect', 'AmountField']