On Oct 6, 2010, at 7:06 AM, Tim Black wrote:

> What is the best way to populate a tgext.menu with new data on every page 
> refresh so it contains only those records returned by a particular database 
> query?  Here's how I'm trying to do it:
> 
> class RootController(BaseController):
>     def __init__(self):
>         for p in DBSession.query(model.Project):
>             navbar_append("Projects || " + p.name, url='/project/' + 
> str(p.id))
> 
> This DOES add a new project to the menu when I add a project to the database, 
> which is great.  But it does NOT do another thing I need it to do:  remove a 
> project from the menu when I delete a project from the database.  That makes 
> me think I need to iterate through existing menu items and selectively delete 
> those that should no longer exist.  If this is the solution, where can I find 
> that list of menu items?  I've read the tgext.menu code and tried to 
> introspect the navbar object, but can't figure out the answer to that 
> question.

I don't know anything about tgext.menu, but two remarks:

  - the above obviously can't work, as it's run only once per controller 
instance. *If* tgext.menu is dynamic enough by itself, you need to stuff this 
code into a place that's run every time in a request - e.g. the variable 
providers.

 - I would use a widget for this. Probably also stuffed into the variable 
providers, and rendered by the master.html.

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