Need advice on passing widget out from EVERY controller

View: New views
3 Messages — Rating Filter:   Alert me  

Need advice on passing widget out from EVERY controller

by Matt Wilson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have a widget that draws a list of links at the top of every page.
I highlight certain links depending on the current page and depending
on some data in my database.

Right now, in every single controller method, I have to instantiate
and return this widget.  It's tedious.  Is there a better way to
always return this widget?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Need advice on passing widget out from EVERY controller

by Christopher Arndt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Matt Wilson schrieb:
> I have a widget that draws a list of links at the top of every page.
> I highlight certain links depending on the current page and depending
> on some data in my database.
>
> Right now, in every single controller method, I have to instantiate
> and return this widget.  It's tedious.  Is there a better way to
> always return this widget?

http://docs.turbogears.org/1.0/Configuration#turbogears-app-cfg-configuration-reference

Look for 'tg.include_widgets'

BTW: You shouldn't need to instantiate the widget for every request.
Instantiate it once in the module where you define it and import it from
there or put the dotted-path for it in tg.include_widgets.

Chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Need advice on passing widget out from EVERY controller

by Matt Wilson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Sep 25, 9:51 am, Christopher Arndt <chris.ar...@...> wrote:

> Matt Wilson schrieb:
>
> > I have a widget that draws a list of links at the top of every page.
> > I highlight certain links depending on the current page and depending
> > on some data in my database.
>
> > Right now, in every single controller method, I have to instantiate
> > and return this widget.  It's tedious.  Is there a better way to
> > always return this widget?
>
> http://docs.turbogears.org/1.0/Configuration#turbogears-app-cfg-confi...
>
> Look for 'tg.include_widgets'
>
> BTW: You shouldn't need to instantiate the widget for every request.
> Instantiate it once in the module where you define it and import it from
> there or put the dotted-path for it in tg.include_widgets.

Hi Chris, thanks for the link.

At first, It seemed like the code in turbogears.controllers.py just
iterates through those widgets and extracts all the relevant
javascript and CSS files and strings, but it didn't add the widget
itself to the template.

Then I saw how it does add the widget, but it changes the name in this
block:

        for i in include_widgets_lst:
            widget = tg_util.load_class(i)
            if isclass(widget):
                widget = widget()
            include_widgets["tg_%s" % i.split(".")[-1]] = widget

So, my original widget was called hw, but in my template, I needed to
refer to it as tg_hw.

I'm posting this here for future reference.

Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbogears@...
To unsubscribe from this group, send email to turbogears+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price!