Beispiel #1
0
    def getMenuItems(self, object, request):
        """Return menu item entries in a TAL-friendly form."""
        result = []
        for name, item in zapi.getAdapters((object, request),
                                           self.getMenuItemType()):
            if item.available():
                result.append(item)

        # Now order the result. This is not as easy as it seems.
        #
        # (1) Look at the interfaces and put the more specific menu entries
        #     to the front.
        # (2) Sort unabigious entries by order and then by title.
        ifaces = list(providedBy(removeSecurityProxy(object)).__iro__)
        result = [(ifaces.index(item._for or Interface),
            item.order, item.title, item) for item in result]
        result.sort()

        result = [
            {'title': item.title,
             'description': item.description,
             'action': item.action,
             'selected': (item.selected() and u'selected') or u'',
             'icon': item.icon,
             'extra': item.extra,
             'submenu': (IBrowserSubMenuItem.providedBy(item) and
                         getMenu(item.submenuId, object, request)) or None}
            for index, order, title, item in result]

        return result
Beispiel #2
0
 def __init__(self, error, request):
     self.error = error
     self.request = request
     self.allow = [
         name for name, adapter
         in zapi.getAdapters((error.object, error.request), Interface)
         if hasattr(adapter, name)]
     self.allow.sort()