def subMenuItem(self, _context, submenu, title, description=u'',
                    action=u'', icon=None, filter=None, permission=None,
                    extra=None, order=0, item_class=None):
        filter = Engine.compile(filter) if filter is not None else None

        if permission is None:
            permission = self.permission

        if order == 0:
            order = _order_counter.get(self.for_, 1)
            _order_counter[self.for_] = order + 1

        if item_class is None:
            item_class = self.subMenuItemClass

        if not IBrowserSubMenuItem.implementedBy(item_class):
            raise ValueError("Item class (%s) must implement IBrowserSubMenuItem" % item_class)

        factory = MenuItemFactory(
            item_class,
            title=title, description=description, icon=icon, action=action,
            filter=filter, permission=permission, extra=extra, order=order,
            _for=self.for_, submenuId=submenu)
        adapter(_context, (factory,), self.menuItemType,
                (self.for_, self.layer), name=title)
Ejemplo n.º 2
0
    def getMenuItems(self, object, request):
        """Return menu item entries in a TAL-friendly form."""

        result = []
        for name, item in 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 unambigious entries by order and then by title.
        ifaces = list(providedBy(removeSecurityProxy(object)).__iro__)
        max_key = len(ifaces)

        def iface_index(item):
            iface = item._for
            if not iface:
                iface = Interface
            if IInterface.providedBy(iface):
                return ifaces.index(iface)
            if isinstance(removeSecurityProxy(object), item._for):
                # directly specified for class, this goes first.
                return -1
            # no idea. This goes last.
            return max_key

        result = [(iface_index(item), item.order, item.title, item)
                  for item in result]
        result.sort()

        result = [{
            'title':
            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
Ejemplo n.º 3
0
    def subMenuItem(self,
                    _context,
                    submenu,
                    title,
                    description=_u(''),
                    action=_u(''),
                    icon=None,
                    filter=None,
                    permission=None,
                    extra=None,
                    order=0,
                    item_class=None):

        if filter is not None:
            filter = Engine.compile(filter)

        if permission is None:
            permission = self.permission

        if order == 0:
            order = _order_counter.get(self.for_, 1)
            _order_counter[self.for_] = order + 1

        if item_class is None:
            item_class = self.subMenuItemClass

        if not IBrowserSubMenuItem.implementedBy(item_class):
            raise ValueError(
                "Item class (%s) must implement IBrowserSubMenuItem" %
                item_class)

        factory = MenuItemFactory(item_class,
                                  title=title,
                                  description=description,
                                  icon=icon,
                                  action=action,
                                  filter=filter,
                                  permission=permission,
                                  extra=extra,
                                  order=order,
                                  _for=self.for_,
                                  submenuId=submenu)
        adapter(_context, (factory, ),
                self.menuItemType, (self.for_, self.layer),
                name=title)
Ejemplo n.º 4
0
    def getMenuItems(self, object, request):
        """Return menu item entries in a TAL-friendly form."""

        result = []
        for name, item in 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 unambigious entries by order and then by title.
        ifaces = list(providedBy(removeSecurityProxy(object)).__iro__)
        max_key = len(ifaces)

        def iface_index(item):
            iface = item._for
            if not iface:
                iface = Interface
            if IInterface.providedBy(iface):
                return ifaces.index(iface)
            if isinstance(removeSecurityProxy(object), item._for):
                # directly specified for class, this goes first.
                return -1
            # no idea. This goes last.
            return max_key

        result = [(iface_index(item), item.order, item.title, item) for item in result]
        result.sort()

        result = [
            {
                "title": 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
Ejemplo n.º 5
0
    def get_public_view_registrations(self, site_manager):
        from opengever.task.response_syncer import BaseResponseSyncerReceiver

        for reg in self.get_adapter_registrations(site_manager):
            if reg.name == '':
                continue

            if reg.name in ALLOWED_ENDPOINTS:
                continue

            if not IBrowserView.implementedBy(reg.factory):
                continue

            if IBrowserSubMenuItem.implementedBy(reg.factory):
                continue

            if self.get_dottedname(reg) in WHITELIST:
                continue

            if len(reg.required) != 2:
                # Only context/request adapters are published.
                continue

            if issubclass(reg.factory, BaseResponseSyncerReceiver):
                # The BaseResponseSyncerReceiver._check_internal_request
                # makes sure that the request is an internal GEVER request.
                # Those requests must be public.
                continue

            permission_role = getattr(reg.factory, '__roles__', None)
            if permission_role is not None:
                continue

            if not self.get_factory(reg).__module__.startswith('opengever.'):
                continue

            yield reg
Ejemplo n.º 6
0
    def get_public_view_registrations(self, site_manager):
        from opengever.task.response_syncer import BaseResponseSyncerReceiver

        for reg in self.get_adapter_registrations(site_manager):
            if reg.name == '':
                continue

            if reg.name in ALLOWED_ENDPOINTS:
                continue

            if not IBrowserView.implementedBy(reg.factory):
                continue

            if IBrowserSubMenuItem.implementedBy(reg.factory):
                continue

            if self.get_dottedname(reg) in WHITELIST:
                continue

            if len(reg.required) != 2:
                # Only context/request adapters are published.
                continue

            if issubclass(reg.factory, BaseResponseSyncerReceiver):
                # The BaseResponseSyncerReceiver._check_internal_request
                # makes sure that the request is an internal GEVER request.
                # Those requests must be public.
                continue

            permission_role = getattr(reg.factory, '__roles__', None)
            if permission_role is not None:
                continue

            if not self.get_factory(reg).__module__.startswith('opengever.'):
                continue

            yield reg
Ejemplo n.º 7
0
 def getMenuItems(self, obj, request):
     obj = removeSecurityProxy(obj)
     menu = tuple(zope.component.getAdapters(
         (obj, request), self.getMenuItemType()))
     # filter out all items which you do not have the permissions for
     result = [ item for name, item in menu if
         check_availability(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 unambigious entries by order and then by title.
     ifaces = list(providedBy(removeSecurityProxy(obj)).__iro__)
     max_key = len(ifaces)
     def iface_index(item):
         iface = item._for
         if not iface:
             iface = Interface
         if zope.interface.interfaces.IInterface.providedBy(iface):
             return ifaces.index(iface)
         if isinstance(removeSecurityProxy(obj), item._for):
             # directly specified for class, this goes first.
             return -1
         # no idea. This goes last.
         return max_key
     result = [(item.order, iface_index(item), item.title, item)
               for item in result]
     result.sort()
     # !+ replace above with super getMenuItems()
     local_url = url.absoluteURL(obj, request)
     site_url = url.absoluteURL(getSite(), request)
     request_url = request.getURL()
     
     items = []
     selected_index = None
     current_pos = -1
     
     for index, (order, iface_index, title, item) in enumerate(result):
         # !+ for some reason, for the generic container listing views, the 
         # context_actions menu comes out with a single item pointing to 
         # "@@index" i.e. itself... we ignore it:
         if item.action=="@@index":
             continue
         
         extra = item.extra or {}
         # if no id has been explictly set, get one in some way or another...
         # !+ID-GENERATION(ah, 17-05-2011) - added call to action_to_id 
         # around item.action as other-wise it returns an invalid @id 
         # attribute (see comment above)
         extra.setdefault("id",
             # try "id", BrowserMenu, bungeni.ui.menu.BrowserSubMenuItem
             # (that picks an id value off item.submenuId) otherwise use
             # the "action" value, zope.browsermenu.BrowserMenuItem
             getattr(item, "id", None) or action_to_id(item.action)
         )
         # !+CSS_ID(mr, may-2011) the CSS menu styling should NOT be based 
         # on element id, it is unnecessarily brittle and limited e.g. what
         # happens if you wish to render a menu twice, on top and bottom of
         # a page? Styling selectors should be connected only via classes
         # (not even element tag names). The use of an element id should be 
         # limited to only known-to-be-unique contrainers in the page e.g.
         # "content", "top-menu-bar", "footer", etc. 
         
         if IBrowserSubMenuItem.providedBy(item):
             submenu = getMenu(item.submenuId, obj, request)
         else:
             submenu = None
             extra["hideChildren"] = True
         
         _url = make_absolute(item.action, local_url, site_url)
         
         if submenu:
             for menu in submenu:
                 menu["url"] = make_absolute(
                     menu["action"], local_url, site_url)
         
         pos = pos_action_in_url(item.action, request_url)
         if pos and pos > current_pos:
             # !+ should really only reset this only once, 
             # and pos *should* always be len(base_url)
             current_pos = pos
             selected_index = index
         
         items.append({
             "title": title,
             "description": item.description,
             "action": item.action,
             "url": _url,
             "selected": u"",
             # !+MENU_ICON(mr, aug-2010) remove, icon always managed via CSS
             "icon": item.icon,
             "extra": extra,
             "submenu": submenu})
     
     if selected_index is not None:
         items[selected_index]["selected"] = u"selected"
     return items
Ejemplo n.º 8
0
    def getMenuItems(self, obj, request):
        obj = removeSecurityProxy(obj)
        menu = tuple(
            zope.component.getAdapters((obj, request), self.getMenuItemType()))
        # filter out all items which you do not have the permissions for
        result = [item for name, item in menu if check_availability(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 unambigious entries by order and then by title.
        ifaces = list(providedBy(removeSecurityProxy(obj)).__iro__)
        max_key = len(ifaces)

        def iface_index(item):
            iface = item._for
            if not iface:
                iface = Interface
            if zope.interface.interfaces.IInterface.providedBy(iface):
                return ifaces.index(iface)
            if isinstance(removeSecurityProxy(obj), item._for):
                # directly specified for class, this goes first.
                return -1
            # no idea. This goes last.
            return max_key

        result = [(item.order, iface_index(item), item.title, item)
                  for item in result]
        result.sort()
        # !+ replace above with super getMenuItems()
        local_url = url.absoluteURL(obj, request)
        site_url = url.absoluteURL(getSite(), request)
        request_url = request.getURL()

        items = []
        selected_index = None
        current_pos = -1

        for index, (order, iface_index, title, item) in enumerate(result):
            # !+ for some reason, for the generic container listing views, the
            # context_actions menu comes out with a single item pointing to
            # "@@index" i.e. itself... we ignore it:
            if item.action == "@@index":
                continue

            extra = item.extra or {}
            # if no id has been explictly set, get one in some way or another...
            # !+ID-GENERATION(ah, 17-05-2011) - added call to action_to_id
            # around item.action as other-wise it returns an invalid @id
            # attribute (see comment above)
            extra.setdefault(
                "id",
                # try "id", BrowserMenu, bungeni.ui.menu.BrowserSubMenuItem
                # (that picks an id value off item.submenuId) otherwise use
                # the "action" value, zope.browsermenu.BrowserMenuItem
                getattr(item, "id", None) or action_to_id(item.action))
            # !+CSS_ID(mr, may-2011) the CSS menu styling should NOT be based
            # on element id, it is unnecessarily brittle and limited e.g. what
            # happens if you wish to render a menu twice, on top and bottom of
            # a page? Styling selectors should be connected only via classes
            # (not even element tag names). The use of an element id should be
            # limited to only known-to-be-unique contrainers in the page e.g.
            # "content", "top-menu-bar", "footer", etc.

            if IBrowserSubMenuItem.providedBy(item):
                submenu = getMenu(item.submenuId, obj, request)
            else:
                submenu = None
                extra["hideChildren"] = True

            _url = make_absolute(item.action, local_url, site_url)

            if submenu:
                for menu in submenu:
                    menu["url"] = make_absolute(menu["action"], local_url,
                                                site_url)

            pos = pos_action_in_url(item.action, request_url)
            if pos and pos > current_pos:
                # !+ should really only reset this only once,
                # and pos *should* always be len(base_url)
                current_pos = pos
                selected_index = index

            items.append({
                "title": title,
                "description": item.description,
                "action": item.action,
                "url": _url,
                "selected": u"",
                # !+MENU_ICON(mr, aug-2010) remove, icon always managed via CSS
                "icon": item.icon,
                "extra": extra,
                "submenu": submenu
            })

        if selected_index is not None:
            items[selected_index]["selected"] = u"selected"
        return items