Back to index

plone3  3.1.7
navigation.py
Go to the documentation of this file.
00001 import zope.deprecation
00002 from plone.i18n.normalizer.interfaces import IIDNormalizer
00003 
00004 from zope.component import getMultiAdapter
00005 from zope.component import queryUtility
00006 from zope.interface import implements
00007 
00008 from Acquisition import aq_base, aq_inner, aq_parent
00009 from Products.Five import BrowserView
00010 
00011 from Products.CMFCore.utils import getToolByName
00012 from Products.CMFPlone import utils
00013 from Products.CMFPlone.browser.interfaces import INavigationPortlet
00014 
00015 class NavigationPortlet(BrowserView):
00016     implements(INavigationPortlet)
00017 
00018     def title(self):
00019         context = aq_inner(self.context)
00020         portal_properties = getToolByName(context, 'portal_properties')
00021         return portal_properties.navtree_properties.name
00022 
00023     def display(self):
00024         tree = self.getNavTree()
00025         root = self.getNavRoot()
00026         return (root is not None and len(tree['children']) > 0)
00027 
00028     def includeTop(self):
00029         context = aq_inner(self.context)
00030         portal_properties = getToolByName(context, 'portal_properties')
00031         return portal_properties.navtree_properties.includeTop
00032 
00033     def navigationRoot(self):
00034         return self.getNavRoot()
00035 
00036     def rootTypeName(self):
00037         root = self.getNavRoot()
00038         return queryUtility(IIDNormalizer).normalize(root.portal_type)
00039 
00040     def createNavTree(self):
00041         context = aq_inner(self.context)
00042         data = self.getNavTree()
00043         properties = getToolByName(context, 'portal_properties')
00044         navtree_properties = getattr(properties, 'navtree_properties')
00045         bottomLevel = navtree_properties.getProperty('bottomLevel', 0)
00046         return context.portlet_navtree_macro(
00047             children=data.get('children', []),
00048             level=1, show_children=True, isNaviTree=True, bottomLevel=bottomLevel)
00049 
00050     def isPortalOrDefaultChild(self):
00051         context = aq_inner(self.context)
00052         root = self.getNavRoot()
00053         return (aq_base(root) == aq_base(context) or
00054                 (aq_base(root) == aq_base(aq_parent(aq_inner(context))) and
00055                 utils.isDefaultPage(context, self.request, context)))
00056 
00057     # Cached lookups
00058 
00059     def getNavRoot(self):
00060         """Get and cache the navigation root"""
00061         if not utils.base_hasattr(self, '_root'):
00062             context = aq_inner(self.context)
00063             portal_url = getToolByName(context, 'portal_url')
00064             portal = portal_url.getPortalObject()
00065 
00066             view = getMultiAdapter((context, self.request),
00067                                    name='navtree_builder_view')
00068             rootPath = view.navigationTreeRootPath()
00069 
00070             if rootPath == portal_url.getPortalPath():
00071                 root = portal
00072             else:
00073                 try:
00074                     root = portal.unrestrictedTraverse(rootPath)
00075                 except (AttributeError, KeyError,):
00076                     root = portal
00077 
00078             self._root = [root]
00079 
00080         return self._root[0]
00081 
00082     def getNavTree(self):
00083         """Calculate the navtree"""
00084         tree = getattr(self, '_navtree', None)
00085         if tree is not None:
00086             return tree
00087         else:
00088             context = aq_inner(self.context)
00089             view = getMultiAdapter((context, self.request),
00090                                    name='navtree_builder_view')
00091             self._navtree = view.navigationTree()
00092             return self._navtree
00093 
00094 zope.deprecation.deprecated(
00095   ('NavigationPortlet', ),
00096    "Plone's portlets are based on plone.app.portlets now. The old portlets "
00097    "will be removed in Plone 4.0."
00098   )