Hello

2007/5/1, Alberto Valverde <[EMAIL PROTECTED]>:
>
>
> On May 1, 2007, at 7:26 AM, kerinin wrote:
>
> >
> > my problem is that i would prefer to pass my widgets in a dictionary
> > to keep the number of arguments being passed to the template down, so
> > instead of passing
> >
> > return dict(widget1=widget1,
> > widget2=widget2,widget3=widget3,widget1data=widget1data,widget2data=wi
> > dget2data,widget3data=widget3data)
> >
> > I would prefer to do this:
> >
> > return dict(widgets=widgets,data=data)
> >
> > Unfortunately if a widget needs to insert a JS or CSS link, the link
> > doesn't get inserted unless the widget itself is one of the arguments
> > being passed to the template.  I'm sure there's a better way to do
> > this - maybe by inserting the JS/CSS link when widgets are displayed,
> > or at least by searching dictionaries lists and tuples to see if they
> > contain widgets.

The retrieve_javascript of a CompoundWidget do this action recursive.

386         def retrieve_javascript(self):
387             """
388             Retrieve the javascript for all the member widgets and
389             get an ordered union of them.
390             """
391             scripts = setlike()
392             for script in self.javascript:
393                 scripts.add(script)
394             for widget in self.iter_member_widgets():
395                 for script in widget.retrieve_javascript():
396                     scripts.add(script)
397             return scripts

from http://trac.turbogears.org/browser/branches/1.0/turbogears/widgets/base.py

>
> Recursing deep into everything thrown into the output dict could be
> too expensive IMO (eg: could potentially consume a SelectResult's
> iterator with 10000 records from the db)

Only if the recursion is done by duck typing. In the CompoundWidget
this recursion is done only if it contains widget (not records).

But do a duck typing in controler is the better option. You don't have
a dependencies to TurboGears Widgets for inject the js or css links.
You can do this defining a retrieve_XXX method (is like an implicit
interface).

>
> > maybe a reserved parameter like
> > 'tg_has_nested_widgets' or something could be defined.
>

This design isn't good. The widgets must have the responsability of
get their dependencies. If CompoundWidget isn't the solution, a custom
widget it is.

Sorry my bad english

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