How does one pre-populate a Python Formish form?

Posted by Jace on Stack Overflow See other posts from Stack Overflow or by Jace
Published on 2010-04-26T03:56:51Z Indexed on 2010/04/26 4:03 UTC
Read the original article Hit count: 290

Filed under:
|

How does one pre-populate a Formish form? The obvious method as per the documentation doesn't seem right. Using one of the provided 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 is a structure like this:

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

However, pre-populating the form using defaults requires this:

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

The dottedish package has a DottedDict object that can convert a nested dict to a dotted dict, but this asymmetry doesn't seem right. Is there a better way to do this?

© Stack Overflow or respective owner

Related posts about python

Related posts about formish