예제 #1
0
 def get_data(self):
     """Get json data to render the fancy tree."""
     query = self.get_query()
     strategy = NavtreeStrategyBase()
     strategy.rootPath = self.root_path
     folder_tree = buildFolderTree(self.portal, None, query, strategy)
     return json.dumps(self.folder_tree_to_fancytree(folder_tree))
예제 #2
0
파일: views.py 프로젝트: IMIO/imio.helpers
 def get_data(self):
     """Get json data to render the fancy tree."""
     query = self.get_query()
     strategy = NavtreeStrategyBase()
     strategy.rootPath = self.root_path
     folder_tree = buildFolderTree(self.portal, None, query, strategy)
     return json.dumps(self.folder_tree_to_fancytree(folder_tree))
예제 #3
0
파일: testNavTree.py 프로젝트: dtgit/dtedu
 def testGetFromRootWithSpecifiedRoot(self):
     rootPath = '/'.join(self.portal.getPhysicalPath())
     strategy = NavtreeStrategyBase()
     strategy.rootPath = rootPath + '/folder1'
     tree = buildFolderTree(self.portal, strategy=strategy)['children']
     self.assertEqual(len(tree), 3)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/folder1/doc11')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/folder1/doc12')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/folder1/doc13')
예제 #4
0
 def testGetFromRootWithSpecifiedRoot(self):
     rootPath = '/'.join(self.portal.getPhysicalPath())
     strategy = NavtreeStrategyBase()
     strategy.rootPath = rootPath + '/folder1'
     tree = buildFolderTree(self.portal, strategy=strategy)['children']
     self.assertEqual(len(tree), 3)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/folder1/doc11')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/folder1/doc12')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/folder1/doc13')
예제 #5
0
    def getCourseItemsInOrder(self):
        """
            Create a flattened out list of portal_catalog queried items in their natural depth first navigation order.
            @param root: Content item which acts as a navigation root
            @param query: Dictionary of portal_catalog query parameters
            @return: List of catalog brains
        """
        root = self
        possible_types = [
            'Kurs', 'Kursabschluss', 'Lerneinheit', 'Document', 'Aufgabe',
            'Audiovideo', 'Checkliste', 'Skill'
        ]
        query = {'portal_type': possible_types}

        # Navigation tree base portal_catalog query parameters
        applied_query = {
            'path': '/'.join(root.getPhysicalPath()),
            'sort_on': 'getObjPositionInParent'
        }

        # Apply caller's filters
        applied_query.update(query)

        # Set the navigation tree build strategy
        # - use navigation portlet strategy as base
        #strategy = DefaultNavtreeStrategy(root)
        strategy = NavtreeStrategyBase()
        strategy.rootPath = '/'.join(root.getPhysicalPath())
        strategy.showAllParents = False
        strategy.bottomLevel = 999
        # This will yield out tree of nested dicts of
        # item brains with retrofitted navigational data
        tree = buildFolderTree(root, root, query, strategy=strategy)

        items = []

        def flatten(children):
            """ Recursively flatten the tree """
            for c in children:
                # Copy catalog brain object into the result
                items.append(c["item"])
                children = c.get("children", None)
                if children:
                    flatten(children)

        flatten(tree["children"])
        return items
예제 #6
0
 def _getTemplatesTree(self):
     '''Create the structure of elements used to display the item templates tree to the item creators.
        We only want to show folders and items the current creator may use, so we do that in 2 steps :
        - a first catalog query that will find every items the creator may use,
          when found, we save the differents paths to these items so we will be able to
          not take into account folder that could exist in the configuration but that would
          be empty because no items into it;
        - when the query is build with list of paths to consider, we use buildFolderTree
          that will build a 'tree' dict with elements and children.'''
     # first query the catalog to see wich items the current user may select
     itemTemplatesPath = '/'.join(self.cfg.itemtemplates.getPhysicalPath())
     itemTemplates = self.cfg.getItemTemplates(as_brains=True,
                                               onlyActive=True,
                                               filtered=True)
     # we need to keep the itemTemplatesPath
     folderPathsToKeep = [
         itemTemplatesPath,
     ]
     # now compute folder paths so only these paths will be passed to buildFolderTree
     # and this method will not consider any other folders
     for itemTemplate in itemTemplates:
         folderPath = '/'.join(itemTemplate.getPath().split('/')[0:-1])
         # keep every folders of folderPath in case the itemtemplate is in a sub/sub/sub/...folder
         while folderPath not in folderPathsToKeep:
             folderPathsToKeep.append(folderPath)
             folderPath = '/'.join(folderPath.split('/')[0:-1])
     query = self.cfg._itemTemplatesQuery(onlyActive=True, filtered=True)
     # we want to query every Folders too
     query['portal_type'] = (query['portal_type'], 'Folder')
     query['path'] = {'query': folderPathsToKeep, 'depth': 1}
     # define a strategy so rootPath is managed ourself or folderTree
     # fails to compute it because query['path']['query'] is a list here...
     strategy = NavtreeStrategyBase()
     strategy.rootPath = itemTemplatesPath
     folderTree = buildFolderTree(self.context, None, query, strategy)
     # the single left problem is the fact that we could have empty folders
     # because we look in the itemTemplatesPath and it returns 'directly contained items' and
     # folders, we can not do anything else using a catalog query...
     # so check children of the root level, if it is an empty folder, we remove it...
     childrenToKeep = []
     for child in folderTree['children']:
         if child['item'].portal_type == 'Folder' and not child['children']:
             continue
         childrenToKeep.append(child)
     folderTree['children'] = childrenToKeep
     return folderTree