Changeset 52385
- Timestamp:
- 01/09/08 16:19:54 (2 years ago)
- Files:
-
- CPS3/products/CPSPortlets/trunk/CHANGES (modified) (1 diff)
- CPS3/products/CPSPortlets/trunk/browser/treenodeview.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
CPS3/products/CPSPortlets/trunk/CHANGES
r52383 r52385 7 7 Bug fixes 8 8 ~~~~~~~~~ 9 - #1866: Dynamic treeview is a performance nightmare. 9 10 - #1879: Highlighting of member space doesn't work for "3tabs" portlet. 10 11 New internal features CPS3/products/CPSPortlets/trunk/browser/treenodeview.py
r32919 r52385 22 22 23 23 """ 24 import logging 25 24 26 from Products.CMFCore.utils import getToolByName 25 27 from AccessControl import Unauthorized … … 29 31 class TreeNodeView(BrowserView): 30 32 33 log = logging.getLogger('CPSPortlets.browser.TreeNodeView') 34 35 def __init__(self, *args, **kwargs): 36 BrowserView.__init__(self, *args, **kwargs) 37 self.utool = getToolByName(self.context, 'portal_url') 38 self.tree_tool = getToolByName(self.context, 'portal_trees') 39 31 40 def getNode(self, root=''): 32 41 """ root is the url of the root node """ 33 utool = getToolByName(self.context, 'portal_url') 42 self.log.debug("getNode: root rpath=%s", root) 43 utool = self.utool 34 44 portal_cpsportlets = getToolByName(self.context, 'portal_cpsportlets') 35 45 36 base_url = utool.getBaseUrl()46 base_url = self.utool.getBaseUrl() 37 47 node = self._getRoot(root) 38 48 object_id = node.getId() … … 43 53 object_url = node.absolute_url_path() 44 54 renderIcon = portal_cpsportlets.renderIcon 45 children = [self.getNode( object.absolute_url_path())46 for objectin self._folderishChildren(node)]55 children = [self.getNode(item['rpath']) 56 for item in self._folderishChildren(node)] 47 57 48 58 if object_url == context_url: … … 73 83 74 84 def _rootRestrictedTraverse(self, path): 75 utool = getToolByName(self.context, 'portal_url') 76 portal_path = utool.getPortalPath() 77 if not path.startswith(portal_path): 78 path = portal_path + path 79 return self.context.restrictedTraverse(path, default=None) 85 86 portal = self.utool.getPortalObject() 87 return portal.restrictedTraverse(path, default=None) 80 88 81 89 def _getRoot(self, root=''): … … 88 96 return self._rootRestrictedTraverse(root) 89 97 98 def _getTreeCache(self, folder, rpath=None): 99 """Find the TreeCache object for given folder. 100 101 Optional rpath can be passed to avoid computing it twice. 102 103 Implementation uses for now a big assumption on the tree naming and uses 104 rpath only 105 """ 106 107 if rpath is None: 108 if folder is None: 109 return 110 rpath = self.utool.getRpath(folder) 111 112 return getattr(self.tree_tool.aq_explicit, rpath.split('/', 1)[0], None) 113 90 114 def _getContent(self, object): 91 115 content = None … … 97 121 98 122 def _hasSubFolders(self, folder): 99 for id, item in folder.objectItems(): 100 if self._isFolderish(item): 101 return True 102 return False 103 104 def _isFolderish(self, object): 105 return ((hasattr(object, 'isPrincipiaFolderish') and 123 rpath = self.utool.getRpath(folder) 124 tc = self._getTreeCache(folder, rpath=rpath) 125 126 if tc is None: 127 # costly fallback 128 for id, item in folder.objectItems(): 129 if self._isFolderish(item): 130 return True 131 return False 132 133 # TODO cache this call for reuse ? 134 depth = len(rpath.split('/')) # depth of children (l-1+1=l) 135 return len(tc.getList(prefix=rpath, 136 start_depth=depth, 137 stop_depth=depth,filter=True)) > 0 138 139 140 def _isFolderish(self, object): 141 return ((hasattr(object, 'isPrincipiaFolderish') and 106 142 object.isPrincipiaFolderish==1) and 107 143 not (object.getId().startswith('.') or … … 109 145 110 146 def _folderishChildren(self, folder): 111 return [item for id, item in folder.objectItems() 112 if self._isFolderish(item)] 147 """GR: now returns part of a treecache structure. """ 148 rpath = self.utool.getRpath(folder) 149 tc = self._getTreeCache(folder, rpath=rpath) 150 if tc is None: 151 # costly BBB fallback 152 return [{'rpath': '/'.join((rpath, id)), 153 'id': id} 154 for id, item in folder.objectItems() 155 if self._isFolderish(item)] 156 depth = len(rpath.split('/')) # depth of children (l-1+1=l) 157 return tc.getList(prefix=rpath, start_depth=depth, stop_depth=depth, 158 filter=True, order=True) 113 159 114 160 def _getFolderItems(self, context_obj=None, show_docs=0, … … 116 162 context_is_portlet=0, recursive=0, **kw): 117 163 164 165 self.log.debug( 166 "Enter _getFolderItems context_obj=%s, context_rpath=%s", 167 context_obj, context_rpath) 168 118 169 context = self.context 119 utool = getToolByName(context, 'portal_url') 120 base_url = utool.getBaseUrl() 170 base_url = self.utool.getBaseUrl() 121 171 122 172 if context_is_portlet: … … 179 229 'coverage': 'coverage'} 180 230 181 for object in bmf.contentValues(): 182 if not self._isFolderish(object): 183 continue 184 object_id = object.getId() 231 for item in self._folderishChildren(bmf): 232 # GR: simply avoid contentValues, did not change anything else 233 # once object variable is set 234 object_id = item['id'] 235 if not bmf.hasObject(object_id): 236 continue 237 object = getattr(bmf, object_id) 185 238 186 239 # filter out objects that cannot be viewed … … 266 319 content = content or self._getContent(object) 267 320 if content is not None: 268 description = getattr(content, 'Descripti childrenon', '')321 description = getattr(content, 'Description', '') 269 322 270 323 object_url = object.absolute_url_path() 271 324 272 325 has_folderish_children = self._hasSubFolders(object) 273 children = [self.getNode(item .absolute_url_path())326 children = [self.getNode(item['rpath']) 274 327 for item in self._folderishChildren(object)] 275 328 if object_url == context_url:
