On Wed, 2007-04-07 at 03:43 -0700, alex23 wrote:
> > This is called by the edit method on the controller and fed the parent/
> > object values it received. It just doesn't feel very elegant, as the
> > controller ends up needing to know a lot about the parent objects. It
> > also means I'm producing a new form each call.
> 
> Of course, 10 mins later I find: 
> http://docs.turbogears.org/1.0/PassingArgumentsToCallables
> 
> Which does help me with what I'm after, but again, doesn't feel
> elegant.

Don't know if it's a 'best practice' but what I have wound up doing is
making all my widgets custom that inherit from TableForm, and putting
them in their own module(s). Then it's pretty easy to add custom
templates and paramaters and keep option callables in their own
namespaces. I define static methods of the widget inside the widget
class that include all my callable option getters. The widget is
*instantiated* statically, outside of controller code, so that anything
that can happen only once does. If it needs runtime field determination,
I pass in a dynamically generated field list, otherwise at render time,
I pass in the default value object. 

Personally, I also render the widget in my controller code instead of in
my template because I find it much easier to see what's getting passed
in as args there instead of in the template. So the the controllers.py
code looks something like this:

( outside of root controller )
page_form = PageFormWidget( ... static args here ... )

( inside individual controller )
page = Page.get( id )
rendered_form = page_form( value=page )
return dict( page, page_form )

( in template )
${page_form} <!-- no need to call, is already rendered -->

Seems to be somewhat manageable. Widgets are confusing but very
powerful. :)

I am, as always, interested in hearing if I am barking up the wrong
tree. ;)
Iain



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