[Twisted-web] gronking nevow forms

Andy Gayton andy at thecablelounge.com
Sun Jun 27 05:06:44 MDT 2004


Andy Gayton wrote:

> Reading through it looks like there are two main ways to express forms; 
> as loose properties, and as methods - or:
> 
> Properties make it easy to present the existing values of an object - 
> but as far as I can tell, they're a one per form kind of thing.  Methods 
> on the other hand are good since as it's easy to throw a bunch of 
> elements in a single form; but it looks horrible trying to load them up 
> with existing data.
> 
> The only way I've found is in the pastebin example:
> 
> ---
> formDefaults = context.locate(iformless.IFormDefaults)
> formDefaults.setDefault('editPasting.text', version.getText())
> formDefaults.setDefault('editPasting.postedBy', version.getAuthor())
> ---
> 
> Is there a more intuitive way of loading values into a method defined 
> form than the pastebin example?

Just chatted with mg on irc - it looks like this sort of thing is 
necessary - so you do have to have a custom render_ something that pokes 
defaults into the form.  There is some nicer syntax to do it with though:

defaults = ctx.locate(IFormDefaults)
myForm = defaults.getAllDefaults('nameOfForm')
myForm['foo'] = 'bar'

and

ctx.locate(IFormDefaults).getAllDefaults('nameOfForm').update(aDictWithEverythingIn)

Thanks mg!

Andy.



More information about the Twisted-web mailing list