コード例 #1
0
ファイル: tools.py プロジェクト: jean/NuPlone
 def __init__(self, *a):
     super(Tools, self).__init__(*a)
     self.user=getSecurityManager().getUser()
     self.anonymous=self.user is None or self.user.getUserName()=="Anonymous User"
     self.portal=utils.getPortal(self.context)
     self.portal_url=self.portal.absolute_url()
     self.navroot=utils.getNavigationRoot(self.context)
     self.navroot_url=self.navroot.absolute_url()
     self.context_url=aq_inner(self.context).absolute_url()
コード例 #2
0
ファイル: tools.py プロジェクト: Python3pkg/NuPlone
 def __init__(self, *a):
     super(Tools, self).__init__(*a)
     self.user = getSecurityManager().getUser()
     self.anonymous = self.user is None or self.user.getUserName(
     ) == "Anonymous User"
     self.portal = utils.getPortal(self.context)
     self.portal_url = self.portal.absolute_url()
     self.navroot = utils.getNavigationRoot(self.context)
     self.navroot_url = self.navroot.absolute_url()
     self.context_url = aq_inner(self.context).absolute_url()
コード例 #3
0
    def build(self, context, request):
        context = aq_inner(context)

        # If we are at a default page use the folder as context for the navtree
        container = aq_parent(context)
        isp = queryMultiAdapter((container, request),
                                name="default_page",
                                default=None)
        if isp is not None and isp.isDefaultPage(context):
            context = container

        contextPath = "/".join(context.getPhysicalPath())
        contextPathLen = len(contextPath)
        parentDepth = (contextPath.count("/") - 1)
        navrootPath = "/".join(getNavigationRoot(context).getPhysicalPath())

        query = {}
        query["path"] = dict(query=contextPath,
                             navtree=True,
                             navtree_start=navrootPath.count("/"))
        query["portal_type"] = typesToList(context)
        query["sort_on"] = "getObjPositionInParent"
        query["sort_order"] = "asc"

        catalog = getToolByName(context, "portal_catalog")
        results = catalog.searchResults(query)
        cache = {}
        cache[navrootPath] = {
            "current": False,
            "currentParent": True,
            "children": []
        }
        for brain in results:
            path = brain.getPath()
            pathLen = len(path)
            parentPath = path.rsplit("/", 1)[0]
            ancestor = current = currentParent = False
            if path == contextPath:
                current = True
            elif contextPathLen > pathLen:
                ancestor = contextPath.startswith(path + "/")
                currentParent = ancestor and path.count("/") == parentDepth

            if brain.exclude_from_nav and not currentParent:
                continue

            oldNode = cache.get(path, None)
            node = {
                "brain": brain,
                "path": path,
                "current": current,
                "currentParent": currentParent,
                "ancestor": ancestor
            }

            oldNode = cache.get(path, None)
            if oldNode is not None:
                oldNode.update(node)
                node = oldNode
            else:
                node["children"] = []
                cache[path] = node

            parentNode = cache.get(parentPath, None)
            if parentNode is None:
                parentNode = cache[parentPath] = dict(children=[node])
            else:
                parentNode["children"].append(node)
            node["parent"] = parentNode

        self.tree = cache
        self.root = cache[navrootPath]
コード例 #4
0
ファイル: navigation.py プロジェクト: jean/NuPlone
    def build(self, context, request):
        context=aq_inner(context)

        # If we are at a default page use the folder as context for the navtree
        container=aq_parent(context)
        isp=queryMultiAdapter((container, request), name="default_page", default=None)
        if isp is not None and isp.isDefaultPage(context):
            context=container

        contextPath="/".join(context.getPhysicalPath())
        contextPathLen=len(contextPath)
        parentDepth=(contextPath.count("/")-1)
        navrootPath="/".join(getNavigationRoot(context).getPhysicalPath())

        query={}
        query["path"]=dict(query=contextPath,
                           navtree=True,
                           navtree_start=navrootPath.count("/"))
        query["portal_type"]=typesToList(context)
        query["sort_on"]="getObjPositionInParent"
        query["sort_order"]="asc"

        catalog=getToolByName(context, "portal_catalog")
        results=catalog.searchResults(query)
        cache={}
        cache[navrootPath]={"current": False, "currentParent": True, "children": []}
        for brain in results:
            path=brain.getPath()
            pathLen=len(path)
            parentPath=path.rsplit("/", 1)[0]
            ancestor=current=currentParent=False
            if path==contextPath:
                current=True
            elif contextPathLen>pathLen:
                ancestor=contextPath.startswith(path+"/")
                currentParent=ancestor and path.count("/")==parentDepth

            if brain.exclude_from_nav and not currentParent:
                continue

            oldNode=cache.get(path, None)
            node={"brain": brain,
                  "path" : path,
                  "current" : current,
                  "currentParent" : currentParent,
                  "ancestor": ancestor }

            oldNode=cache.get(path, None)
            if oldNode is not None:
                oldNode.update(node)
                node=oldNode
            else:
                node["children"]=[]
                cache[path]=node

            parentNode=cache.get(parentPath, None)
            if parentNode is None:
                parentNode=cache[parentPath]=dict(children=[node])
            else:
                parentNode["children"].append(node)
            node["parent"]=parentNode


        self.tree=cache
        self.root=cache[navrootPath]
コード例 #5
0
ファイル: tools.py プロジェクト: euphorie/NuPlone
 def navroot(self):
     return utils.getNavigationRoot(self.context)
コード例 #6
0
ファイル: tabs.py プロジェクト: euphorie/NuPlone
 def getRoot(self):
     return getNavigationRoot(self.context)
コード例 #7
0
ファイル: tabs.py プロジェクト: jean/NuPlone
 def getRoot(self):
     return getNavigationRoot(self.context)