Back to index

plone3  3.1.7
Functions
plone.app.layout.navigation.root Namespace Reference

Functions

def getNavigationRoot

Function Documentation

def plone.app.layout.navigation.root.getNavigationRoot (   context,
  relativeRoot = None 
)
Get the path to the root of the navigation tree. If context or one of
its parents until (but not including) the portal root implements
INavigationRoot, return this.

Otherwise, if an explicit root is set in navtree_properties or given as
relativeRoot, use this. If the property is not set or is set to '/', use 
the portal root.

Definition at line 8 of file root.py.

00008 
00009 def getNavigationRoot(context, relativeRoot=None):
00010     """Get the path to the root of the navigation tree. If context or one of
00011     its parents until (but not including) the portal root implements
00012     INavigationRoot, return this.
00013 
00014     Otherwise, if an explicit root is set in navtree_properties or given as
00015     relativeRoot, use this. If the property is not set or is set to '/', use 
00016     the portal root.
00017     """
00018 
00019     portal_url = getToolByName(context, 'portal_url')
00020     
00021     if not relativeRoot:
00022         portal_properties = getToolByName(context, 'portal_properties')
00023         navtree_properties = getattr(portal_properties, 'navtree_properties')
00024         relativeRoot = navtree_properties.getProperty('root', None)
00025 
00026     portal = portal_url.getPortalObject()
00027     obj = context
00028     while not INavigationRoot.providedBy(obj) and aq_base(obj) is not aq_base(portal):
00029         obj = utils.parent(obj)
00030     if INavigationRoot.providedBy(obj) and aq_base(obj) is not aq_base(portal):
00031         return '/'.join(obj.getPhysicalPath())
00032 
00033     rootPath = relativeRoot
00034     portalPath = portal_url.getPortalPath()
00035     contextPath = '/'.join(context.getPhysicalPath())
00036 
00037     if rootPath:
00038         if rootPath == '/':
00039             return portalPath
00040         else:
00041             if len(rootPath) > 1 and rootPath[0] == '/':
00042                 return portalPath + rootPath
00043             else:
00044                 return portalPath
00045 
00046     # This code is stolen from Sprout, but it's unclear exactly how it
00047     # should work and the test from Sprout isn't directly transferable
00048     # to testNavTree.py, since it's testing something slightly different.
00049     # Hoping Sidnei or someone else with a real use case can do this.
00050     # The idea is that if the 'root' variable is set to '', you'll get
00051     # the virtual root. This should probably also be used by the default
00052     # search, as well as the tabs and breadcrumbs. Also, the text in
00053     # prefs_navigation_form.cpt should be updated if this is re-enabled.
00054     #
00055     # Attempt to get use the virtual host root as root if an explicit
00056     # root is not set
00057     # if rootPath == '':
00058     #    request = getattr(context, 'REQUEST', None)
00059     #    if request is not None:
00060     #        vroot = request.get('VirtualRootPhysicalPath', None)
00061     #        if vroot is not None:
00062     #            return '/'.join(('',) + vroot[len(portalPath):])
00063 
00064     # Fall back on the portal root
00065     if not rootPath:
        return portalPath

Here is the call graph for this function:

Here is the caller graph for this function: