[Zope3-Users] Using IPathAdapter on menuItem

Florian Lindner mailinglists at xgm.de
Sat Apr 30 12:52:03 EDT 2005


Hey,
a IMO good solution just came into my mind while taking a nap. I implemented 
the solution in 5 minutes and it workes.
It registered a view:

    <page
        name="toHomeFolder"
        for="*"
        permission="zope.Public"
        class=".views.toHomeFolder"
        layer="centershock"
        menu="CSnavMenu"
        title="home folder" />

and the view class:

class toHomeFolder(object):
    """ Makes a redirect to the homefolder of the principal. """
    def __call__(self):
        from zope.app.zapi import absoluteURL, getUtility
        from CS.Homefolder.interfaces import ICSHomeFolderManager
        hfm = getUtility(ICSHomeFolderManager)
        req = self.request
        URL = absoluteURL(hfm.getHomeFolder(req.principal.id), req)
        req.response.redirect(URL)


Works perfect. :-)

Florian

Am Samstag, 30. April 2005 18:09 schrieb Garrett Smith:
> Looking at the code, I don't see an easy way to do what you want to do.
> The menuItem directive doesn't give you any hooks. It would be nice if
> it supported a class attribute where you could specify your own browser
> menu item class (or mixin) like the page directive.
>
> If you're desparate enough, you can always create your own directive to
> register a menu item with an alternative browser menu item class. That
> class would dynamically provide the 'action' attribute as a property
> value, evaluating whatever path expression it got in the ZCML. If you
> want to go down that road, just copy/paste the existing code,
> substituting YourBrowserMenuItem for BrowserMenuItem for the
> registration code in z/a/publisher/browser/menumeta.py (line 165).
>
> Sorry, I know this is a pain, but the alternative would be to submit a
> feature request and wait (probably a long time :)
>
>  -- Garrett
>
> Florian Lindner wrote:
> > Am Donnerstag, 28. April 2005 21:45 schrieb Garrett Smith:
> >> I think you want this:
> >>
> >>   principal/++adapter++hf/@@absolute_url
> >>
> >> Personally, I don't care for the shortcut syntax -- it's not clear
> >> what's going on (at all). It also doesn't appear to support what
> >> you're trying to do.
> >
> > Sorry, I need to come back to you.
> > The syntax above works perfect in ZPT templates but I can not make it
> > working in menuItem action="..." the string I put in the action
> > attribute is simply concatenated to the URL and not interpreted.
> >
> > Thanks,
> >
> > Florian
> >
> >> Florian Lindner wrote:
> >>> Am Donnerstag, 28. April 2005 16:43 schrieb Garrett Smith:
> >>>> I dont know whether action is evaluated or just passed through.
> >>>> But I use the notation:
> >>>>
> >>>>   foo/++adapter++myadapter/bar
> >>>>
> >>>> for path adapters. There might be a short-cut syntax, but I don't
> >>>> recall what it is.
> >>>
> >>> I've found at that the problem is another one:
> >>>
> >>> Iterating of the keys of the object works:
> >>>
> >>>         <div tal:repeat="itm request/principal/hf:keys">
> >>>             <span tal:replace="itm">test</span>
> >>>         </div>
> >>>
> >>> hf returns a object derived from IContainer for the Interface and
> >>> BTreeContainer for the Implementation.
> >>>
> >>> But I want the URL of the object hf returns. Everything I tried with
> >>> absolute_url does not work. Of course I can add a method which
> >>> returns zapi.absoluteURL(self, self.context) to the object but I'm
> >>> sure there a better way. How to get the URL of the object...
> >>>
> >>> Thx,
> >>>
> >>> Florian
> >>>
> >>>> Florian Lindner wrote:
> >>>>> Hello,
> >>>>> I've a a IPathAdapter:
> >>>>>
> >>>>>   <adapter
> >>>>>       for="zope.security.interfaces.IPrincipal"
> >>>>>       provides="zope.app.traversing.interfaces.IPathAdapter"
> >>>>>       factory=".homefolder.getHomeFolder"
> >>>>>       name="hf" />
> >>>>>
> >>>>> (from Stephans HomeFolderManager)
> >>>>>
> >>>>> Now I want a menu item that is pointing to that homefolder. How
> >>>>> can I do that?
> >>>>>
> >>>>>     <menuItem
> >>>>>         action="principal/hf"
> >>>>> 	[...]" />
> >>>>>
> >>>>> Does not work?
> >>>>>
> >>>>> Thx,
> >>>>>
> >>>>> Florian
> >>>>> _______________________________________________
> >>>>> Zope3-users mailing list
> >>>>> Zope3-users at zope.org
> >>>>> http://mail.zope.org/mailman/listinfo/zope3-users


More information about the Zope3-users mailing list