I'm currently trying to build a viewlet-based menu. As any common menu, it 
should consist of entries, which link in my case to certain object views. If 
such a link is clicked, the menu entry should change (no link) to denote that 
the entry is selected.

Therefore I built a base class that looks like the following:

class MenuEntryViewlet(ViewletBase):

    def update(self):
        site_path = absoluteURL(getParent(getSiteManager(self)), self.request)
        self.link = site_path + self.link

    render = ViewPageTemplateFile('pt_desktop/menuentry.pt')

    def iscurrent(self):
        current_url = absoluteURL(getParent(getParent(self)), self.request)
        if current_url == self.link:
            return True
            return False

The page template either returns an entry with a link or without one, 
regarding to view/iscurrent. Now I can inherit menu entries and configure 
them to show up in the menu like this:

class ME_Home(MenuEntryViewlet):

    label = u"Startseite"
    link = "/index.html"  # Relative to my Site Object

My problem is that the update() function which sets the link does not always 
work. The link should always include the URL of the local site object, which 
is does not when a 404 page is displayed, therefore all menu entries have 
invalid links.

Does anyone know why, or does someone have a better suggestion to my problem?

Best Regards,

GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
Zope3-users mailing list

Reply via email to