Replies inline...

On Dec 1, 4:29 pm, Paul Johnston <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am developing a form that uses nested widgets. The main form is Order
> and there is a variable number of Contact forms embedded (Contact has a
> foreign key to Order).
>
> Nested widgets work great, using TableForm and RepeatingFieldSet.
> Parsing the form parameters back to dictionaries and lists works great.
> When saving the data to the database, I'm using SqlSchema from
> FormEncode. This works ok for doing individual rows, but I have to
> manually iterate to do the nested structure, something like:
> order_schema.to_python(**kw)
> for c in kw['contacts']:
>   contact_schema.to_python(c)
>
> I wondered, is it possible to do all this in one go? I am going to be
> attempting a much more complicated nested form soon and the ability to
> do this would be very helpful. Especially as I need to add an check to
> avoid parameter tampering attacks, basically
> Contact.get(c['id']).orderID == kw['id']
> If this is not currently possible, I will have a go at writing a patch
> to add support.
>

Paul, why the "to_python()" ?? If you have an SQLObject (let's call it
Person) with three fields in it (firstname, lastname, homephone), you
can add a fieldset to your widget form called "personinfo" and then in
your controller save the data into a new Person object like this:
p = Person(**personinfo).  Am I missing something?  Are you worried
about a security issue?

> While I'm here, a couple of other questions:
> 1) Can you build a widget form automatically from an SQLObject? I've
> seen mention of FastData, but I couldn't find any docs or examples.

Yes you can build a widget form automatically from an SQLObject.
FastDataController does this, take a look at this to get started, and
use the source!
http://www.turbogears.org/widgets/tutorials/DataGridWidget.html
(here's a tip that's probably not listed on that page -- you can get
your fields to appear on the form in a certain order by adding a member
variable called "field_order" to your SQLObject class.  Check out the
SQLObject docs on how to use it)

> 2) Is it possible to combine a widgetform and a dataobject, into a
> single object? I'd like to generate my nested form from a template, just
> using widgets for the controls, not the form layouts. The template code
> for this is getting way out of hand with form.display_field_for('xx' ..
> It would be great to just have the columns replaced by controls, so I
> could do $order.name to get the appropriate text box.

I think the FastData stuff is what you're looking for.  Once you've got
it working, make a copy of the fastdata source and call it MyFastData
(or something), so you can change the source to display the fields
using any custom widgets you might have.  Start by looking in the
"fields_for" function...

hope this helps!
-ian


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to