Matthew Bevan schrieb:
>> How do I find out that iz is mounted to '/foo' in MyController itself?
> 
> Investigate the cherrypy._cputil.get_object_trail() function.
> 
> For example, here is how I generate a breadcrumb list in my CMS:
> 
> def breadcrumbs():
>       cherry_trail = cherrypy._cputil.get_object_trail()
>       href = '/'
>       crumbs = [['/', 'Home']]
>       for item in cherry_trail:
>               if isinstance(item[1], RootController): continue
>               
>               if isinstance(item[1], Atom):
>                       href = "%s%s/" % (href, item[0])
>                       crumbs.append([href, item[1].q.title])
>       
>       crumbs[-1][0] = None
>       return crumbs

Thanks for the code! I've generalized that a bit and adapted it to my purpose:

class MyController(controllers.Controller):

    def _get_root_url(self):
        return self.breadcrumbs[-1][0]
    root_url = property(_get_root_url)

    def _get_breadcrumbs(self):
        try:
            return self._breadcrumbs
        except AttributeError:
            cherry_trail = cherrypy._cputil.get_object_trail()
            href = '/'
            crumbs = [('/', 'Home')]
            for item in cherry_trail:
                if isinstance(item[1], controllers.RootController):
                    continue
                if isinstance(item[1], controllers.Controller):
                    href = "%s%s/" % (href, item[0])
                    crumbs.append((href,
                      getattr(item[1], 'title', item[1].__class__.__name__)))
            self._breadcrumbs = crumbs
            return crumbs
    breadcrumbs = property(_get_breadcrumbs)


Maybe somebody else will find this useful too.

Chris


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