Let's take, for example, a User `Schema` where the site admin sets the
number of requested phone numbers:
class MySchema(Schema):
name = validators.String(not_empty=True)
phone_1 = validators.PhoneNumber(not_empty=True)
phone_2 = validators.PhoneNumber(not_empty=True)
phone_3 = validators.PhoneNumber(not_empty=True)
...
Somehow I thought I could simply do:
class MySchema(Schema):
name = validators.String(not_empty=True)
def __init__(self, *args, **kwargs):
requested_phone_numbers = Session.query(...).scalar()
for n in xrange(requested_phone_numbers):
key = 'phone_{0}'.format(n)
kwargs[key] = validators.PhoneNumber(not_empty=True)
Schema.__init__(self, *args, **kwargs)
since I read in [FormEncode docs][1]:
> Validators use instance variables to store their customization
> information. You can use either subclassing or normal instantiation to
> set these.
and `Schema` is called in docs as a Compound Validator and is a
subclass of `FancyValidator` so I guessed it's correct.
But this does not work: simply added `phone_n` are ignored and only
`name` is required.
Also I tried both overriding `__new__` and `__classinit__` before
asking with no success...
Thanks for your support
P.S.: I asked this on [StackOverflow][2] too, sorry if it can be
considered crossposting but this task -- I consider it not so uncommon
-- is driving me mad.
[1]: http://formencode.org/Validator.html#other-validator-usage
[2]:
http://stackoverflow.com/questions/6773957/formencode-schema-add-fields-dynamically
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.