How to pre-populate a Python Formish form?

How can I pre-fill a Formish form? The obvious method as per the documentation seems wrong. Using one of the following examples:

import formish, schemaish structure = schemaish.Structure() structure.add( 'a', schemaish.String() ) structure.add( 'b', schemaish.Integer() ) schema = schemaish.Structure() schema.add( 'myStruct', structure ) form = formish.Form(schema, 'form') 

If we pass this a valid request object:

 form.validate(request) 

The output of this structure is as follows:

 {'myStruct': {'a': 'value', 'b': 0 }} 

However, pre-populating the form with defaults requires the following:

 form.defaults = {'myStruct.a': 'value', 'myStruct.b': 0} 

The dottedish package has a DottedDict object that can convert a nested dict to a point dict, but this asymmetry seems wrong. Is there a better way to do this?

+7
python
source share
1 answer

No, you don’t need to use dotted dict, you can easily use the post-validate dict style to pre-populate the form:

 form.defaults={'myStruct': {'a': None, 'b': 'default_value'}} 

perhaps there is an old version of formish, try updating the libraries.

+1
source share

All Articles