Ejemplo n.º 1
0
    def add_container_menu_items(self, context, container):
        request = self.request
        # add a menu item for each user workspace, if we are in an
        # IWorkspaceSectionLayer
        # !+ if user is logged in or if request.layer_data

        if (interfaces.IWorkspaceSectionLayer.providedBy(request)
                or interfaces.IWorkspaceSchedulingSectionLayer.providedBy(
                    request)):
            try:
                workspaces = IAnnotations(request)["layer_data"].get(
                    "workspaces")
            except:
                workspaces = []
            log.info("%s got user workspaces: %s" % (self, workspaces))
            base_url_path = "/workspace"
            for workspace in workspaces:
                log.info("appending menu item for user workspace: %s" %
                         str(workspace))
                self.items.append(
                    url.get_menu_item_descriptor(
                        workspace.full_name,
                        pos_action_in_url(
                            "/workspace/obj-%s" % workspace.group_id,
                            request.getURL()), base_url_path,
                        "obj-%s" % workspace.group_id))

        _url = url.absoluteURL(container, request)

        if IReadContainer.providedBy(container):
            #XXX should be the same in all containers ?
            container = proxy.removeSecurityProxy(container)
            for name, item in container.items():
                if context is None:
                    selected = False
                else:
                    selected = url.same_path_names(context.__name__, name)
                item = proxy.removeSecurityProxy(item)
                if IDCDescriptiveProperties.providedBy(item):
                    title = item.title
                else:
                    props = IDCDescriptiveProperties(item)
                    title = props.title
                # only items with valid title
                if title is not None:
                    self.items.append(
                        url.get_menu_item_descriptor(title, selected, _url,
                                                     name))
        default_view_name = queryDefaultViewName(container, self.request)
        default_view = component.queryMultiAdapter((container, self.request),
                                                   name=default_view_name)
        if hasattr(default_view, "title") and default_view.title is not None:
            self.items.insert(
                0,
                url.get_menu_item_descriptor(
                    default_view.title,
                    sameProxiedObjects(container, self.context), _url))
Ejemplo n.º 2
0
    def add_container_menu_items(self, context, container):
        request = self.request
        # add a menu item for each user workspace, if we are in an
        # IWorkspaceSectionLayer
        # !+ if user is logged in or if request.layer_data
        if interfaces.IWorkspaceSectionLayer.providedBy(request):
            try:
                workspaces = IAnnotations(request)["layer_data"].get(
                    "workspaces")
            except:
                workspaces = []
            log.info("%s got user workspaces: %s" % (self, workspaces))
            base_url_path = "/workspace"
            for workspace in workspaces:
                log.info("appending menu item for user workspace: %s" %
                         str(workspace))
                self.items.append(
                    url.get_menu_item_descriptor(
                        workspace.full_name,
                        pos_action_in_url(
                            "/workspace/obj-%s" % workspace.group_id,
                            request.getURL()), base_url_path,
                        "obj-%s" % workspace.group_id))

        _url = url.absoluteURL(container, request)

        if IReadContainer.providedBy(container):
            #XXX should be the same in all containers ?
            container = proxy.removeSecurityProxy(container)
            for name, item in container.items():
                if context is None:
                    selected = False
                else:
                    selected = url.same_path_names(context.__name__, name)
                item = proxy.removeSecurityProxy(item)
                if IDCDescriptiveProperties.providedBy(item):
                    title = item.title
                else:
                    props = IDCDescriptiveProperties(item)
                    title = props.title
                # only items with valid title
                if title is not None:
                    self.items.append(
                        url.get_menu_item_descriptor(title, selected, _url,
                                                     name))
        default_view_name = queryDefaultViewName(container, self.request)
        default_view = component.queryMultiAdapter((container, self.request),
                                                   name=default_view_name)
        if hasattr(default_view, "title") and default_view.title is not None:
            self.items.insert(
                0,
                url.get_menu_item_descriptor(
                    default_view.title,
                    sameProxiedObjects(container, self.context), _url))
Ejemplo n.º 3
0
    def add_zcml_menu_items(self, container):
        """Add the list of ZCML menu items (if any) for this top-level 
        container. Top-level section given by container may define a menu 
        in ZCML with naming convention: <container_name>_navigation. 
        """
        # !+ turn this into a utility
        zcml_menu_name_template = "%s_navigation"
        try:
            menu_name = zcml_menu_name_template % container.__name__
            menu = component.getUtility(IBrowserMenu, name=menu_name)
            items = menu.getMenuItems(container, self.request)
        except (Exception, ):
            debug.log_exc(sys.exc_info(), log_handler=log.debug)
            return []

        # OK, do any necessary post-processing of each menu item
        local_url = url.absoluteURL(container, self.request)
        site_url = url.absoluteURL(getSite(), self.request)
        request_url = self.request.getURL()
        default_view_name = queryDefaultViewName(container, self.request)
        selection = None
        for item in sorted(items,
                           key=lambda item: item["action"],
                           reverse=True):
            action = item["action"]
            if default_view_name == action.lstrip("@@"):
                _url = local_url
                if selection is None:
                    selected = sameProxiedObjects(container, self.context)
            else:
                _url = make_absolute(action, local_url, site_url)
                if selection is None:
                    selected = pos_action_in_url(action, request_url)
            item["url"] = _url
            item["selected"] = selected and u"selected" or u""
            if selected:
                # self is marker
                selection = self
                selected = False
            self.items.append(item)
Ejemplo n.º 4
0
 def add_zcml_menu_items(self, container):
     """Add the list of ZCML menu items (if any) for this top-level 
     container. Top-level section given by container may define a menu 
     in ZCML with naming convention: <container_name>_navigation. 
     """
     # !+ turn this into a utility
     zcml_menu_name_template = "%s_navigation"
     try:
         menu_name = zcml_menu_name_template % container.__name__
         menu = component.getUtility(IBrowserMenu, name=menu_name)
         items = menu.getMenuItems(container, self.request)
     except (Exception,):
         debug.log_exc(sys.exc_info(), log_handler=log.debug)
         return []
     
     # OK, do any necessary post-processing of each menu item
     local_url = url.absoluteURL(container, self.request)
     site_url = url.absoluteURL(getSite(), self.request)
     request_url = self.request.getURL()
     default_view_name = queryDefaultViewName(container, self.request)
     selection = None
     for item in sorted(items, key=lambda item: item["action"], reverse=True):
         action = item["action"]
         if default_view_name==action.lstrip("@@"):
             _url = local_url
             if selection is None:
                 selected = sameProxiedObjects(container, self.context)
         else:
             _url = make_absolute(action, local_url, site_url)
             if selection is None:
                 selected = pos_action_in_url(action, request_url)
         item["url"] = _url
         item["selected"] = selected and u"selected" or u""
         if selected:
             # self is marker
             selection = self
             selected = False
         self.items.append(item)