X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/57603f1daf24cf21708e8f3231009fcae12282bd..b53a45e7e79b31d0b6b44df0405366cc8a2fd016:/pymin/validatedclass.py?ds=sidebyside diff --git a/pymin/validatedclass.py b/pymin/validatedclass.py index 3ad8aec..b94f2b2 100644 --- a/pymin/validatedclass.py +++ b/pymin/validatedclass.py @@ -70,11 +70,11 @@ attributes using Field instances. For example: Nice, ugh? """ -__ALL__ = ('Field', 'ValidatedClass') +__all__ = ('Field', 'ValidatedClass') from formencode import Invalid from formencode.schema import Schema -from formencode.validators import FancyValidator, OneOf, CIDR, Int +from formencode.validators import FancyValidator # FIXME not thread safe (use threadlocal?) # This is a counter to preserve the order of declaration of fields (class @@ -232,6 +232,9 @@ if __name__ == '__main__': name = Field(formencode.validators.String(not_empty=True)) age = Field(formencode.validators.Int(max=110, if_empty=None, if_missing=None)) + def __init__(self, *args, **kwargs): + ValidatedClass.__init__(self, *args, **kwargs) + self.a_dict = dict() # Some global validation after individual fields validation def chained_validator(self, fields, state): if 'Jr' in fields['name'] and fields['age'] > 25: @@ -253,6 +256,11 @@ if __name__ == '__main__': # Use the order of fields declaration assert t.name == 'Graham' + # we can use regular fields too + t.a_dict.update(dict(python=True)) + assert 'python' in t.a_dict + assert t.a_dict['python'] is True + t = Test('Graham', 20) assert t.name == 'Graham' and t.age == 20