John Lorance schrieb:
> I'm converting a TG1 app with TG1 style widgets and am finding that a
> code pattern implemented to add widgets on the fly in TG1 doesn't work
> in TG2/TW.   Basically, in an existing form's update_params method,
> new fields were being added to a fieldset based upon parameters of the
> request/data in model.  This strategy doesn't seem to work in TW.  So,
> my questions is what is the best way to create a form that adds
> widgets dynamically?
> 
> So far it seems that I need to instantiate a new form widget object
> for each request and pass it a fields parameter that is the set of
> fields needed for the given request. For example,
> 
> myfields = [TextField("a"), TextField("b")]... etc
> myform = MyForm("formname", fields=myfields)
> myform.display(**params) # pass non-field items in display.
> 
> Is this the best approach, or is there a better way that can more
> mimic what was possible with TG1 widgets?

If this worked with TG1 it was pure luck that you didn't run into 
concurrency issues. TW tries to lock-down widgets after instantiation 
time. This obviously has it's limits, but in this case it caught the 
"abuse".

By modifying widgets like that at runtime, you modified a single 
instance which was used to render concurrent requests. If the load is 
not to heavy, that works. If it ramps up, errors will creep in when two 
requests modify the widget before it is rendered.

So, the answer is: it isn't possible, and it wasn't really a good idea 
in TG1 as well :)

Now the question is: what kind of dynamic alterations did you actually 
need? Can you please give an example of that, then we can think about a 
conformant solution.

Diez

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