Frederik Elwert wrote:
> I am currently writing a web survey application where users can generate
> their own surveys.
> 
> I have the form generation in place, so forms are generated from the
> user's survey definition file. Now I want to add validation. As far as I
> understood the concept of FormEncode, it expects me to know what kind of
> values I expect when setting up the Schema.
> 
> E.g., from the docs:
> 
> class EmailForm(formencode.Schema):
>     allow_extra_fields = True
>     filter_extra_fields = True
>     email = formencode.validators.Email(not_empty=True)
> 
> Now I can't "hardcode" that I have a variable of type email, I just have
> information about the variables like:
> 
> [('v1', {'type': 'email', 'required': True}), ('v2', {'type: 'int',
> 'max': 100})]
> 
> Now I want to set up a Schema from this information, equivalent to this:
> 
> class SurveyForm(formencode.Schema):
>     allow_extra_fields = True
>     filter_extra_fields = True
>     v1 = formencode.validators.Email(not_empty=True)
>     v2 = formencode.validators.Int(not_empty=False, max=100)
> 
> Is it somehow possible to generate Schema definitions dynamically like
> this?

cust_schema = formencode.Schema(allow_extra_fields=True, 
filter_extra_fields=True)
cust_schema.add_field('v1', formencode.validators.Email(not_empty=True)
cust_schema.add_field('v2', formencode.validators.Int(not_empty=False, 
max=100)

> By the way, Ian suggested that there were min and max keyword arguments
> for the Int validator in the "FormEncode form validators" thread, but I
> don't get them to work:
> 
>>>> val = validators.Int(max=5)
>>>> val.to_python('10')
> 10

Somehow I thought they were there generally, but they weren't.  In the 
FormEncode trunk they work.

-- 
Ian Bicking : [EMAIL PROTECTED] : http://blog.ianbicking.org

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to