示例#1
0
    def getNavTree(self, _marker=None):
        if _marker is None:
            _marker = []

        context = aq_inner(self.context)

        # Full nav query, not just the tree for 'this' item
        queryBuilder = SitemapQueryBuilder(self.data.navigation_root())
        query = queryBuilder()

        strategy = getMultiAdapter((context, self.data), INavtreeStrategy)

        # Add explicit path to query, since the sitemap query uses the root of
        # the site
        nav_root = self.getNavRoot()

        if nav_root:
            query['path'] = {
                'query': "/".join(nav_root.getPhysicalPath()),
                'depth': self.bottomLevel
            }

        return buildFolderTree(context,
                               obj=context,
                               query=query,
                               strategy=strategy)
示例#2
0
    def getNavTree(self, _marker=[]):
        context = aq_inner(self.context)

        # Special case - if the root is supposed to be pruned, we need to
        # abort here        

        queryBuilder = getMultiAdapter((context, self.data), INavigationQueryBuilder)
        strategy = getMultiAdapter((context, self.data), INavtreeStrategy)
        
        obj = context
        if queryBuilder.portlet.root == "/Members" and self.context == self.context.portal_url.getPortalObject() and len(self.context.REQUEST.steps) > 0 and self.context.REQUEST.steps[-1] in ('author','personalize_form',):            
            userid = None
            traverse_subpath = self.context.REQUEST.traverse_subpath
            if len(traverse_subpath) > 0:
                userid = traverse_subpath[0]
            else:
                currentuser = getSecurityManager().getUser()
                if currentuser <> None:
                    userid = currentuser.getId()
            if userid <> None:
                currentPath = "/".join(self.context.getPhysicalPath()) + "/Members/" + userid
                try:
                    obj = context.restrictedTraverse(currentPath)
                except AttributeError:
                    obj = None
                if obj == None:
                    obj = context        
        return buildFolderTree(context, obj=obj, query=queryBuilder(), strategy=strategy)
示例#3
0
    def getTabObject(self, tabUrl='', tabPath=None):
        if tabUrl == self.portal_state.navigation_root_url():
            # We are at the navigation root
            return ''
        if tabPath is None:
            # get path for current tab's object
            try:
                # we are in Plone > 3.0.x
                tabPath = tabUrl.split(self.site_url)[-1]
            except AttributeError:
                # we are in Plone 3.0.x world
                tabPath = tabUrl.split(self.portal_url)[-1]

            if tabPath == '' or '/view' in tabPath:
                # It's either the 'Home' or Image tab. It can't have
                # any dropdown.
                return ''

            if tabPath.startswith("/"):
                tabPath = tabPath[1:]
            elif tabPath.endswith('/'):
                # we need a real path, without a slash that might appear
                # at the end of the path occasionally
                tabPath = str(tabPath.split('/')[0])

            if '%20' in tabPath:
                # we have the space in object's ID that has to be
                # converted to the real spaces
                tabPath = tabPath.replace('%20', ' ').strip()

        if tabPath == '':
            return ''

        portal = self.portal_state.portal()
        portal_path = '/'.join(portal.getPhysicalPath())

        if portal_path != self.navroot_path:
            portal = portal.restrictedTraverse(self.navroot_path)
        tabObj = portal.restrictedTraverse(tabPath, None)

        if tabObj is None:
            # just in case we have missed any possible path
            # in conditions above
            return ''

        strategy = getMultiAdapter((tabObj, self.data), INavtreeStrategy)
        queryBuilder = DropdownQueryBuilder(tabObj)
        query = queryBuilder()

        data = buildFolderTree(tabObj,
                               obj=tabObj,
                               query=query,
                               strategy=strategy)

        bottomLevel = self.data.bottomLevel or self.properties.getProperty(
            'bottomLevel', 0)

        return self.recurse(children=data.get('children', []),
                            level=1,
                            bottomLevel=bottomLevel).strip()
        def buildSpecialtiesFolderTree():
            """Return a buildFolderTree-style tree representing every SpecialtiesFolder and its descendents.

            More specifically, do a buildFolderTree for each SpecialtiesFolder, then merge the
            results into one big tree.
            """
            portal_catalog = getToolByName(self, 'portal_catalog')
            tree = {'children': []}
            for specialtiesFolder in portal_catalog(
                    portal_type='FSDSpecialtiesFolder'):
                subtree = buildFolderTree(self,
                                          query={
                                              'path': {
                                                  'query':
                                                  specialtiesFolder.getPath()
                                              },
                                              'portal_type': 'FSDSpecialty'
                                          })
                subtree['currentItem'] = False
                subtree['currentParent'] = False
                subtree['item'] = specialtiesFolder
                subtree['depth'] = 0
                # Let's see if that drives the stylesheets crazy. Otherwise,
                # I'm going to have to increment the 'depth' keys in the whole rest of the tree.
                tree['children'].append(subtree)
            return tree
示例#5
0
 def siteMap(self):
     context = aq_inner(self.context)
     queryBuilder = SitemapQueryBuilder(context)
     query = queryBuilder()
     strategy = getMultiAdapter((context, self), INavtreeStrategy)
     strategy.showAllParents = False
     return buildFolderTree(context, obj=context, query=query, strategy=strategy)
示例#6
0
    def build_nav_tree(self, root, query):
        """
        Create a list of portal_catalog queried items

        @param root: Content item which acts as a navigation root

        @param query: Dictionary of portal_catalog query parameters

        @return: Dictionary of navigation tree
        """
        context = aq_inner(self.context)
        # Navigation tree base portal_catalog query parameters
        applied_query = {
            'path': '/'.join(root.getPhysicalPath()),
            'sort_on': 'getObjPositionInParent',
            'review_state': 'published'
        }
        # Apply caller's filters
        applied_query.update(query)
        # - use navigation portlet strategy as base
        strategy = DefaultNavtreeStrategy(root)
        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(context,
                               obj=context,
                               query=query,
                               strategy=strategy)
        return tree
示例#7
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))
示例#8
0
    def update(self):
        self.result = []
        sections = ['noticias', 'opinion']
        self.navroot_path = getNavigationRoot(self.context)
        self.data = Assignment(root=self.navroot_path)
        self.year = datetime.date.today().strftime("%Y")
        for section in sections:
            catalog_news = self.context.portal_catalog({'portal_type': 'Folder',
                                'path': '%s/%s/' % (self.navroot_path, section)})
            if catalog_news:
                tab = catalog_news[0].getObject()
                strategy = getMultiAdapter((tab, self.data), INavtreeStrategy)
                queryBuilder = DropdownQueryBuilder(tab)
                query = queryBuilder()

                if query['path']['query'] != self.navroot_path:
                    news_dict = buildFolderTree(tab, obj=tab, query=query,
                        strategy=strategy)
                    self.result += news_dict.get('children', [])
                else:
                    news_dict = {}

        for item in self.result:
            if self.context.getId() == item['id']:
                item['is_selected'] = True
            else:
                item['is_selected'] = False
示例#9
0
 def getNavTree(self, _marker=None):
     if _marker is None:
         _marker = []
     context = aq_inner(self.context)
     queryBuilder = getMultiAdapter((context, self.data), IPolicyNavigationQueryBuilder)
     strategy = getMultiAdapter((context, self.data), IPolicyNavtreeStrategy)
     return buildFolderTree(context, obj=context, query=queryBuilder(), strategy=strategy)
    def render_tree(self, relPath=None, query=None, limit=LIMIT, offset=0):
        self.show_more = True
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()
        source = self.bound_source

        if query is not None:
            source.navigation_tree_query = query
        strategy = getMultiAdapter((portal, self), INavtreeStrategy)
        if relPath is not None:
            root_path = portal_state.navigation_root_path()
            rel_path = root_path + '/' + relPath
            strategy.rootPath = rel_path
        if not source.selectable_filter.criteria:
            data = buildFolderTree(portal, obj=portal,
                                   query=source.navigation_tree_query,
                                   strategy=strategy)
        else:
            result = self.getRelated(limit=10)
            if len(result) < LIMIT:
                self.show_more = False
            data = self.brainsToTerms(result)
        result = self.filterSelected(data)
        return self.recurse_template(children=result.get('children', []),
                                     level=1,
                                     offset=offset + limit)
 def update(self):
     query = self.request.get('q', None)
     self.tab = self.request.get('tab', None)
     uids = None
     if self.tab == 'recent':
         pass
     elif self.tab == 'clipboard':
         brains = list(self.search(''))[:2]
         uids = [b.UID for b in brains]
     result = self.search(query, uids=uids)
     strategy = SitemapNavtreeStrategy(self.context)
     result = [strategy.decoratorFactory({'item': node}) for node in result]
     if self.tab == 'content-tree':
         portal_state = getMultiAdapter((self.context, self.request),
                                           name=u'plone_portal_state')
         portal = portal_state.portal()
         query_tree = {'sort_on': 'getObjPositionInParent',
                       'sort_order': 'asc',
                       'is_default_page': False}
         strategy.rootPath = '/Plone'
         data = buildFolderTree(portal,
                            obj=portal,
                            query=query_tree,
                            strategy=strategy)
         result = data.get('children', [])
     self.level = 1
     self.children = result
示例#12
0
 def testGetFromRootWithDecoratorFactory(self):
     class Strategy(NavtreeStrategyBase):
         def decoratorFactory(self, node):
             node['foo'] = True
             return node
     tree = buildFolderTree(self.portal, strategy=Strategy())['children']
     self.assertEqual(tree[0]['foo'], True)
示例#13
0
    def getTabSubTree(self, tabUrl='', tabPath=None):
        if tabPath is None:
            # get path for current tab's object
            tabPath = tabUrl.split(self.portal.absolute_url())[-1]

            if tabPath == '' or '/view' in tabPath:
                return ''

            if tabPath.startswith('/'):
                tabPath = tabPath[1:]
            elif tabPath.endswith('/'):
                # we need a real path, without a slash that might appear
                # at the end of the path occasionally
                tabPath = str(tabPath.split('/')[0])

            if '%20' in tabPath:
                # we have the space in object's ID that has to be
                # converted to the real spaces
                tabPath = tabPath.replace('%20', ' ').strip()

        tabObj = self.portal.restrictedTraverse(tabPath, None)
        if tabObj is None:
            return ''

        strategy = CustomNavtreeStrategy(tabObj)
        queryBuilder = NavigationTreeQueryBuilder(tabObj, self.depth)
        query = queryBuilder()
        data = buildFolderTree(tabObj,
                               obj=tabObj,
                               query=query,
                               strategy=strategy)

        return self.recurse(children=data.get('children', []), level=1)
示例#14
0
    def chapters(self):
        if getattr(self, '_chapters', None) is None:
            tree = buildFolderTree(self.context, query={
                'path': '/'.join(self.context.getPhysicalPath())})
            tree = BookTocTree()(tree)

            def flatten(node):
                yield node
                for nodes in map(flatten, node.get('children', [])):
                    for subnode in nodes:
                        yield subnode

            self._chapters = {}
            for position, node in enumerate(flatten(tree)):
                brain = node['item']
                if node['toc_number']:
                    title = ' '.join((node['toc_number'], brain.Title))
                else:
                    title = brain.Title

                self._chapters[brain.getPath()] = {
                    'brain': brain,
                    'title': title,
                    'position': position,
                    'reader_url': '%s/@@book_reader_view' % brain.getURL()}

        return self._chapters
    def update(self):
        self.navroot_path = getNavigationRoot(self.context)
        self.data = {}

        tab = aq_inner(self.context)

        portal_type = getattr(self.context, 'portal_type', None)

        if hasattr(self.context, 'section') and (portal_type == 'collective.nitf.content' or
                                                 portal_type == 'openmultimedia.contenttypes.gallery'):

            section = self.context.section
            oid = idnormalizer.normalize(section, 'es')
            news_folder = getattr(self.context.portal_url, 'noticias', None)
            if news_folder:
                tab = getattr(news_folder, oid, None)

        #XXX this should be generalized... this hardcoded cases are so so lame.. sorry
        # if  getattr(self.context, 'portal_type', None) == 'collective.polls.poll':
        #     polls_folder = getattr(self.context.portal_url, 'encuestas', None)
        #     if polls_folder:
        #         tab = polls_folder

        if not tab:
            return

        strategy = getMultiAdapter((tab, Assignment(root=self.navroot_path)),
                                   INavtreeStrategy)
        queryBuilder = DropdownQueryBuilder(tab)
        query = queryBuilder()

        if query['path']['query'] != self.navroot_path:
            self.data = buildFolderTree(tab, obj=tab, query=query, strategy=strategy)
    def testGetFromRootWithCurrentFolderishNavtreePruned(self):
        context = self.portal.folder2.folder21

        class Strategy(NavtreeStrategyBase):

            def subtreeFilter(self, node):
                return (node['item'].getId != 'folder2')
            showAllParents = True

        query = {'path': {'query': '/'.join(context.getPhysicalPath()),
                          'navtree': 1}}
        rootPath = '/'.join(self.portal.getPhysicalPath())
        tree = buildFolderTree(self.portal, query=query,
                               obj=context, strategy=Strategy())['children']
        self.assertEqual(len(tree), 6)
        self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
        self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
        self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
        self.assertEqual(tree[3]['item'].getPath(), rootPath + '/folder1')
        self.assertEqual(len(tree[3]['children']), 0)
        self.assertEqual(tree[4]['item'].getPath(), rootPath + '/link1')
        self.assertEqual(tree[5]['item'].getPath(), rootPath + '/folder2')
        self.assertEqual(len(tree[5]['children']), 1)
        self.assertEqual(tree[5]['children'][0][
                         'item'].getPath(), rootPath + '/folder2/folder21')
        self.assertEqual(len(tree[5]['children'][0]['children']), 2)
        self.assertEqual(tree[5]['children'][0]['children'][0][
                         'item'].getPath(), rootPath + '/folder2/folder21/doc211')
        self.assertEqual(tree[5]['children'][0]['children'][1][
                         'item'].getPath(), rootPath + '/folder2/folder21/doc212')
示例#17
0
    def CategoryMap(self):
        context = aq_inner(self.context)

        query = {}
        query['portal_type'] = ['BlogCategory']

        strategy = getMultiAdapter((context, self), INavtreeStrategy)

        #some modifications for ftw.blog
        strategy.showAllParents = True
        strategy.excludedIds = {}

        blogutils = getUtility(IBlogUtils, name='ftw.blog.utils')
        bloglevel = blogutils.getBlogRoot(context)

        if bloglevel is None:
            return None

        strategy.rootPath = '/'.join(bloglevel.getPhysicalPath()) + \
            '/categories'

        return buildFolderTree(context,
                               obj=context,
                               query=query,
                               strategy=strategy)
示例#18
0
 def getNavTree(self, _marker=[]):
     context = aq_inner(self.context)
     queryBuilder = getMultiAdapter((context, self.data), INavigationQueryBuilder)
     strategy = NavtreeStrategyBase(context, self.data)
     result = buildFolderTree(context, obj=context, query=queryBuilder(), strategy=strategy)
     result, _ = _filter(result)
     return result
 def testGetFromRoot(self):
     tree = buildFolderTree(self.portal)['children']
     rootPath = '/'.join(self.portal.getPhysicalPath())
     self.assertEqual(len(tree), 6)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
     self.assertEqual(tree[3]['item'].getPath(), rootPath + '/folder1')
     self.assertEqual(len(tree[3]['children']), 3)
     self.assertEqual(tree[3]['children'][0]['item'].getPath(),
                      rootPath + '/folder1/doc11')
     self.assertEqual(tree[3]['children'][1]['item'].getPath(),
                      rootPath + '/folder1/doc12')
     self.assertEqual(tree[3]['children'][2]['item'].getPath(),
                      rootPath + '/folder1/doc13')
     self.assertEqual(tree[4]['item'].getPath(), rootPath + '/link1')
     self.assertEqual(tree[5]['item'].getPath(), rootPath + '/folder2')
     self.assertEqual(len(tree[5]['children']), 5)
     self.assertEqual(tree[5]['children'][0]['item'].getPath(),
                      rootPath + '/folder2/doc21')
     self.assertEqual(tree[5]['children'][1]['item'].getPath(),
                      rootPath + '/folder2/doc22')
     self.assertEqual(tree[5]['children'][2]['item'].getPath(),
                      rootPath + '/folder2/doc23')
     self.assertEqual(tree[5]['children'][3]['item'].getPath(),
                      rootPath + '/folder2/file21')
     self.assertEqual(tree[5]['children'][4]['item'].getPath(),
                      rootPath + '/folder2/folder21')
     self.assertEqual(len(tree[5]['children'][4]['children']), 2)
     self.assertEqual(
         tree[5]['children'][4]['children'][0]['item'].getPath(),
         rootPath + '/folder2/folder21/doc211')
     self.assertEqual(
         tree[5]['children'][4]['children'][1]['item'].getPath(),
         rootPath + '/folder2/folder21/doc212')
示例#20
0
    def getNavTree(self, _marker=None):
        if _marker is None:
            _marker = []

        context = aq_inner(self.context)

        # Full nav query, not just the tree for 'this' item
        nav_root = self.getNavRoot()

        queryBuilder = SitemapQueryBuilder(nav_root)
        query = queryBuilder()

        # Add explicit path to query, since the sitemap query uses the root of
        # the site
        if nav_root:
            query['path'] = {
                'query': "/".join(nav_root.getPhysicalPath()),
                'depth': self.data.get('bottomLevel', 3)
            }

        data = dict(self.data)
        data['root_uid'] = data['root']

        strategy = NavtreeStrategy(context, object_factory(**data))

        return buildFolderTree(context,
                               obj=context,
                               query=query,
                               strategy=strategy)
    def testGetFromRootWithCurrentNavtreePruned(self):
        context = self.portal.folder1.doc11

        class Strategy(NavtreeStrategyBase):
            def subtreeFilter(self, node):
                return (node['item'].getId != 'folder1')

            showAllParents = True

        query = {
            'path': {
                'query': '/'.join(context.getPhysicalPath()),
                'navtree': 1
            }
        }
        rootPath = '/'.join(self.portal.getPhysicalPath())
        tree = buildFolderTree(self.portal,
                               query=query,
                               obj=context,
                               strategy=Strategy())['children']
        self.assertEqual(len(tree), 6)
        self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
        self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
        self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
        self.assertEqual(tree[3]['item'].getPath(), rootPath + '/folder1')
        self.assertEqual(len(tree[3]['children']), 1)
        self.assertEqual(tree[3]['children'][0]['item'].getPath(),
                         rootPath + '/folder1/doc11')
        self.assertEqual(tree[4]['item'].getPath(), rootPath + '/link1')
        self.assertEqual(tree[5]['item'].getPath(), rootPath + '/folder2')
        self.assertEqual(len(tree[5]['children']), 0)
 def testGetFromRootWithCurrentNavtree(self):
     context = self.portal.folder1.doc11
     query = {
         'path': {
             'query': '/'.join(context.getPhysicalPath()),
             'navtree': 1
         }
     }
     tree = buildFolderTree(self.portal, query=query)['children']
     rootPath = '/'.join(self.portal.getPhysicalPath())
     self.assertEqual(len(tree), 6)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
     self.assertEqual(tree[3]['item'].getPath(), rootPath + '/folder1')
     self.assertEqual(len(tree[3]['children']), 3)
     self.assertEqual(tree[3]['children'][0]['item'].getPath(),
                      rootPath + '/folder1/doc11')
     self.assertEqual(tree[3]['children'][1]['item'].getPath(),
                      rootPath + '/folder1/doc12')
     self.assertEqual(tree[3]['children'][2]['item'].getPath(),
                      rootPath + '/folder1/doc13')
     self.assertEqual(tree[4]['item'].getPath(), rootPath + '/link1')
     self.assertEqual(tree[5]['item'].getPath(), rootPath + '/folder2')
     self.assertEqual(len(tree[5]['children']), 0)
示例#23
0
文件: navbar.py 项目: a25kk/hfph
 def siteNavStrategy(self):
     context = aq_inner(self.context)
     selected_tab = self.selected_portal_tab
     obj = api.portal.get()[selected_tab]
     path = {'query': '/'.join(obj.getPhysicalPath()),
             'navtree': 1,
             'navtree_start': 2,
             'depth': 2}
     query = {
         'path': path,
         'review_state': 'published',
         'portal_type': ('hph.sitecontent.mainsection',
                         'hph.sitecontent.contentpage',
                         'hph.lectures.coursefolder')
     }
     strategy = SitemapNavtreeStrategy(obj)
     strategy.rootPath = '/'.join(obj.getPhysicalPath())
     strategy.showAllParents = True
     strategy.bottomLevel = 999
     tree = buildFolderTree(context, obj, query, strategy)
     items = []
     for c in tree['children']:
         item = {}
         item['item'] = c['item']
         item['children'] = c.get('children', '')
         item['itemid'] = c['normalized_id']
         item_id = c['normalized_id']
         if item_id == context.getId():
             item['class'] = 'active'
         else:
             item['class'] = ''
         item['parent'] = self.compute_parent_marker(item_id)
         items.append(item)
     return items
示例#24
0
    def render_tree(self, relPath=None, query=None, limit=LIMIT, offset=0):
        self.show_more = True
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()
        source = self.bound_source

        if query is not None:
            source.navigation_tree_query = query
        strategy = getMultiAdapter((portal, self), INavtreeStrategy)
        if relPath is not None:
            root_path = portal_state.navigation_root_path()
            rel_path = root_path + '/' + relPath
            strategy.rootPath = rel_path
        if not source.selectable_filter.criteria:
            data = buildFolderTree(portal,
                                   obj=portal,
                                   query=source.navigation_tree_query,
                                   strategy=strategy)
        else:
            result = self.getRelated(limit=10)
            if len(result) < LIMIT:
                self.show_more = False
            data = self.brainsToTerms(result)
        result = self.filterSelected(data)
        return self.recurse_template(children=result.get('children', []),
                                     level=1,
                                     offset=offset + limit)
示例#25
0
文件: view.py 项目: seantis/ftw.book
    def get_tree(self, book):
        """Returns an unlimited, recursive navtree of the book.
        """
        query = {
            'path': '/'.join(book.getPhysicalPath())}

        return buildFolderTree(book, obj=book, query=query)
示例#26
0
文件: navigation.py 项目: a25kk/anv
    def build_nav_tree(self, root, query):
        """
        Create a list of portal_catalog queried items

        @param root: Content item which acts as a navigation root

        @param query: Dictionary of portal_catalog query parameters

        @return: Dictionary of navigation tree
        """

        # Navigation tree base portal_catalog query parameters
        applied_query = {
            'path': '/'.join(root.getPhysicalPath()),
            'sort_on': 'getObjPositionInParent',
            'review_state': 'published'
        }
        # Apply caller's filters
        applied_query.update(query)
        # - use navigation portlet strategy as base
        strategy = DefaultNavtreeStrategy(root)
        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)
        return tree
示例#27
0
文件: navbar.py 项目: a25kk/hfph
 def navStrategy(self, obj, types, start):
     context = aq_inner(self.context)
     root = getNavigationRoot(context)
     path = {'query': '/'.join(obj.getPhysicalPath()),
             'navtree': 1,
             'navtree_start': start}
     query = {
         'path': path,
         'review_state': 'published',
         'portal_type': types,
         'sort_order': 'getObjPositionInParent'
     }
     root_obj = context.unrestrictedTraverse(root)
     strategy = DefaultNavtreeStrategy(root_obj)
     strategy.rootPath = '/'.join(root_obj.getPhysicalPath())
     strategy.showAllParents = False
     strategy.topLevel = 2
     strategy.bottomLevel = 999
     tree = buildFolderTree(root_obj, root_obj,
                            query, strategy=NavtreeStrategyBase())
     items = []
     for c in tree['children']:
         item = {}
         item['item'] = c['item']
         item['children'] = c.get('children', '')
         item['current'] = c['currentItem']
         item['is_parent'] = c['currentParent']
         item_id = c['item'].getId
         item['itemid'] = item_id
         item['marker'] = self.compute_navitem_marker(item_id)
         items.append(item)
     return items
 def testGetFromRoot(self):
     tree = buildFolderTree(self.portal)['children']
     rootPath = '/'.join(self.portal.getPhysicalPath())
     self.assertEqual(len(tree), 6)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
     self.assertEqual(tree[3]['item'].getPath(), rootPath + '/folder1')
     self.assertEqual(len(tree[3]['children']), 3)
     self.assertEqual(tree[3]['children'][0][
                      'item'].getPath(), rootPath + '/folder1/doc11')
     self.assertEqual(tree[3]['children'][1][
                      'item'].getPath(), rootPath + '/folder1/doc12')
     self.assertEqual(tree[3]['children'][2][
                      'item'].getPath(), rootPath + '/folder1/doc13')
     self.assertEqual(tree[4]['item'].getPath(), rootPath + '/link1')
     self.assertEqual(tree[5]['item'].getPath(), rootPath + '/folder2')
     self.assertEqual(len(tree[5]['children']), 5)
     self.assertEqual(tree[5]['children'][0][
                      'item'].getPath(), rootPath + '/folder2/doc21')
     self.assertEqual(tree[5]['children'][1][
                      'item'].getPath(), rootPath + '/folder2/doc22')
     self.assertEqual(tree[5]['children'][2][
                      'item'].getPath(), rootPath + '/folder2/doc23')
     self.assertEqual(tree[5]['children'][3][
                      'item'].getPath(), rootPath + '/folder2/file21')
     self.assertEqual(tree[5]['children'][4][
                      'item'].getPath(), rootPath + '/folder2/folder21')
     self.assertEqual(len(tree[5]['children'][4]['children']), 2)
     self.assertEqual(tree[5]['children'][4]['children'][0][
                      'item'].getPath(), rootPath + '/folder2/folder21/doc211')
     self.assertEqual(tree[5]['children'][4]['children'][1][
                      'item'].getPath(), rootPath + '/folder2/folder21/doc212')
示例#29
0
    def CategoryMap(self):
        context = aq_inner(self.context)

        query = {}
        query['portal_type'] = ['BlogCategory']

        strategy = getMultiAdapter((context, self), INavtreeStrategy)

        #some modifications for ftw.blog
        strategy.showAllParents = True
        strategy.excludedIds = {}

        blogutils = getUtility(IBlogUtils, name='ftw.blog.utils')
        bloglevel = blogutils.getBlogRoot(context)

        if bloglevel is None:
            return None

        strategy.rootPath = '/'.join(bloglevel.getPhysicalPath()) + \
            '/categories'

        return buildFolderTree(context,
                               obj=context,
                               query=query,
                               strategy=strategy)
示例#30
0
 def navStrategy(self):
     context = aq_inner(self.context)
     if IFolderish.providedBy(context):
         root = '/'.join(context.getPhysicalPath())
     else:
         parent = context.__parent__
         root = '/'.join(parent.getPhysicalPath())
     query = {
         'path': root,
         'review_state': 'published',
         'portal_type': 'meetshaus.jmscontent.contentpage',
         'sort_order': 'getObjPositionInParent'
     }
     root_obj = context.unrestrictedTraverse(root)
     strategy = DefaultNavtreeStrategy(root_obj)
     strategy.rootPath = '/'.join(root_obj.getPhysicalPath())
     strategy.showAllParents = False
     strategy.bottomLevel = 999
     tree = buildFolderTree(root_obj, root_obj, query, strategy=strategy)
     items = []
     for c in tree['children']:
         item = {}
         item['item'] = c['item']
         item['children'] = c.get('children', '')
         item['itemid'] = c['normalized_id']
         item_id = c['normalized_id']
         if item_id == context.getId():
             item['class'] = 'active'
         else:
             item['class'] = ''
         items.append(item)
     return items
示例#31
0
    def chapters(self):
        if getattr(self, '_chapters', None) is None:
            tree = buildFolderTree(
                self.context,
                query={'path': '/'.join(self.context.getPhysicalPath())})
            tree = BookTocTree()(tree)

            def flatten(node):
                yield node
                for nodes in map(flatten, node.get('children', [])):
                    for subnode in nodes:
                        yield subnode

            self._chapters = {}
            for position, node in enumerate(flatten(tree)):
                brain = node['item']
                if node['toc_number']:
                    title = ' '.join((node['toc_number'], brain.Title))
                else:
                    title = brain.Title

                self._chapters[brain.getPath()] = {
                    'brain': brain,
                    'title': title,
                    'position': position,
                    'reader_url': '%s/@@book_reader_view' % brain.getURL()
                }

        return self._chapters
示例#32
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))
示例#33
0
 def testGetFromRootWithDecoratorFactory(self):
     class Strategy(NavtreeStrategyBase):
         def decoratorFactory(self, node):
             node['foo'] = True
             return node
     tree = buildFolderTree(self.portal, strategy=Strategy())['children']
     self.assertEqual(tree[0]['foo'], True)
    def getTabObject(self, tabUrl='', tabPath=None):
        if tabUrl == self.portal_state.navigation_root_url():
            # We are at the navigation root
            return ''
        if tabPath is None:
            # get path for current tab's object
            try:
                # we are in Plone > 3.0.x
                tabPath = tabUrl.split(self.site_url)[-1]
            except AttributeError:
                # we are in Plone 3.0.x world
                tabPath = tabUrl.split(self.portal_url)[-1]

            if tabPath == '' or '/view' in tabPath:
                # It's either the 'Home' or Image tab. It can't have
                # any dropdown.
                return ''

            if tabPath.startswith("/"):
                tabPath = tabPath[1:]
            elif tabPath.endswith('/'):
                # we need a real path, without a slash that might appear
                # at the end of the path occasionally
                tabPath = str(tabPath.split('/')[0])

            if '%20' in tabPath:
                # we have the space in object's ID that has to be
                # converted to the real spaces
                tabPath = tabPath.replace('%20', ' ').strip()

        if tabPath == '':
            return ''

        portal = self.portal_state.portal()
        portal_path = '/'.join(portal.getPhysicalPath())
        # Check to see if we are using a navigation root. If we are
        # virtual hosting the navigation root as its own domain,
        # the tabPath is no longer rooted at the main portal.
        if portal_path != self.navroot_path:
            portal = portal.restrictedTraverse(self.navroot_path)
        tabObj = portal.restrictedTraverse(tabPath, None)

        if tabObj is None:
            # just in case we have missed any possible path
            # in conditions above
            return ''

        strategy = getMultiAdapter((tabObj, self.data), INavtreeStrategy)
        queryBuilder = DropdownQueryBuilder(tabObj)
        query = queryBuilder()

        data = buildFolderTree(tabObj, obj=tabObj, query=query,
                               strategy=strategy)

        bottomLevel = self.data.bottomLevel or self.properties.getProperty(
            'bottomLevel', 0)

        return self.recurse(children=data.get('children', []), level=1,
                            bottomLevel=bottomLevel).strip()
    def render_tree(self):
        content = closest_content(self.context)
        source = self.bound_source

        strategy = getMultiAdapter((content, self), INavtreeStrategy)
        data = buildFolderTree(content, obj=content, query=source.navigation_tree_query, strategy=strategy)

        return self.recurse_template(children=data.get("children", []), level=1)
示例#36
0
 def testGetFromFixed(self):
     rootPath = '/'.join(self.portal.getPhysicalPath())
     query = {'path' : rootPath + '/folder1'}
     tree = buildFolderTree(self.portal, query=query)['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')
示例#37
0
 def testGetFromRootWithCustomQuery(self):
     query = {'portal_type' : 'Document'}
     tree = buildFolderTree(self.portal, query=query)['children']
     rootPath = '/'.join(self.portal.getPhysicalPath())
     self.assertEqual(len(tree), 3)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
示例#38
0
 def testGetFromFixed(self):
     rootPath = '/'.join(self.portal.getPhysicalPath())
     query = {'path' : rootPath + '/folder1'}
     tree = buildFolderTree(self.portal, query=query)['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')
示例#39
0
 def testCurrentParent(self):
     self.loginAsPortalOwner()
     self.portal.invokeFactory('Document', 'doc')
     context = self.portal.doc1
     tree = buildFolderTree(self.portal, obj=context)['children']
     for t in tree:
         if t['item'].getId == 'doc':
             self.assertEqual(t['currentParent'], False)
示例#40
0
    def getNavTree(self, _marker=None):
        if _marker is None:
            _marker = []
        context = aq_inner(self.context)
        queryBuilder = getMultiAdapter((context, self.data), INavigationQueryBuilder)
        strategy = getMultiAdapter((context, self.data), INavtreeStrategy)

        return buildFolderTree(context, obj=context, query=queryBuilder(), strategy=strategy)
    def getNavTree(self, _marker=[]):
        context = aq_inner(self.context)
        queryBuilder = getMultiAdapter((context, self),
                                       INavigationQueryBuilder)
        strategy = getMultiAdapter((context, self), INavtreeStrategy)

        return buildFolderTree(context, obj=context,
                               query=queryBuilder(), strategy=strategy)
 def testCurrentParent(self):
     self.loginAsPortalOwner()
     self.portal.invokeFactory('Document', 'doc')
     context = self.portal.doc1
     tree = buildFolderTree(self.portal, obj=context)['children']
     for t in tree:
         if t['item'].getId == 'doc':
             self.assertEqual(t['currentParent'], False)
 def testGetFromRootWithCustomQuery(self):
     query = {'portal_type': 'Document'}
     tree = buildFolderTree(self.portal, query=query)['children']
     rootPath = '/'.join(self.portal.getPhysicalPath())
     self.assertEqual(len(tree), 3)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
 def getNavTree(self, _marker=None):
     if _marker is None:
         _marker = []
     context = aq_inner(self.context)
     queryBuilder = NavtreeQueryBuilder(self.getNavRoot())
     strategy = getMultiAdapter((context, self.data), INavtreeStrategy)
     tree = buildFolderTree(context, obj=context, query=queryBuilder(), strategy=strategy)
     tree = self._expandFolderTree(tree, queryBuilder, strategy)
     return tree
示例#45
0
    def navigationTree(self):
        context = aq_inner(self.context)

        queryBuilder = NavtreeQueryBuilder(context)
        query = queryBuilder()

        strategy = getMultiAdapter((context, self), INavtreeStrategy)

        return buildFolderTree(context, obj=context, query=query, strategy=strategy)
示例#46
0
    def _build_navtree(self):
        # we generate our navigation out of the sitemap. so we can use the
        # highspeed navtree generation, and use it's caching features too.
        query = SuperFishQueryBuilder(self.context)()
        query['path']['depth'] = self.settings.menu_depth
        query['path']['query'] = self.navigation_root_path

        # no special strategy needed, so i kicked the INavtreeStrategy lookup.
        return buildFolderTree(self.context, obj=self.context, query=query)
示例#47
0
    def siteMap(self):
        context = aq_inner(self.context)

        queryBuilder = SitemapQueryBuilder(context)
        query = queryBuilder()

        strategy = getMultiAdapter((context, self), INavtreeStrategy)

        return buildFolderTree(context, obj=context, query=query, strategy=strategy)
示例#48
0
 def __call__(self):
     context = self.context
     query = {
         'path': '/'.join(context.getPhysicalPath())}
     raw_tree = buildFolderTree(context, obj=context, query=query)
     toc_tree = BookTocTree()
     tree = toc_tree(raw_tree)
     self.tree = tree
     return self.template()
示例#49
0
    def _build_navtree(self):
        # we generate our navigation out of the sitemap. so we can use the
        # highspeed navtree generation, and use it's caching features too.
        query = SuperFishQueryBuilder(self.context)()
        query['path']['depth'] = self.menu_depth
        query['path']['query'] = self.navigation_root_path

        # no special strategy needed, so i kicked the INavtreeStrategy lookup.
        return buildFolderTree(self.context, obj=self.context, query=query)
示例#50
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')
示例#51
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')
示例#52
0
    def navigationTree(self):
        context = aq_inner(self.context)

        queryBuilder = NavtreeQueryBuilder(context)
        query = queryBuilder()

        strategy = getMultiAdapter((context, self), INavtreeStrategy)

        return buildFolderTree(context, obj=context, query=query, strategy=strategy)
示例#53
0
 def testGetFromFixedAndDepth(self):
     rootPath = '/'.join(self.portal.getPhysicalPath())
     query = {'path' : rootPath + '/folder2', 'depth' : 1}
     tree = buildFolderTree(self.portal, query=query)['children']
     self.assertEqual(len(tree), 5)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/folder2/doc21')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/folder2/doc22')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/folder2/doc23')
     self.assertEqual(tree[3]['item'].getPath(), rootPath + '/folder2/file21')
     self.assertEqual(tree[4]['item'].getPath(), rootPath + '/folder2/folder21')
示例#54
0
    def getNavTree(self, _marker=[]):
        context = aq_inner(self.context)
        queryBuilder = getMultiAdapter((context, self.data),
                                       INavigationQueryBuilder)
        strategy = AttachmentsNavtreeStrategy(context, self.data)

        return buildFolderTree(context,
                               obj=context,
                               query=queryBuilder(),
                               strategy=strategy)
示例#55
0
    def update(self):
        """
        only grab second level of links.  For instance, if you are in the root,
        do not show this, but if you are in a folder inside the root, show this.
        
        Examples,
        
        root/future students
            -will show and future students will be base
        root/future students/undergraduate/file
            -same as earlier
        root/
            -will not show
        
        """
        super(CurrentSectionNav, self).update()

        site = self.portal_state.portal()
        context = aq_inner(self.context)
        utils = getToolByName(context, 'plone_utils')
        self.shoulddisplay = True

        if utils.isDefaultPage(
                context,
                self.request) or not utils.isStructuralFolder(context):
            context = aq_parent(context)

        if not ISectionNavigation.providedBy(context):
            self.shoulddisplay = False
            return

        context_path = context.getPhysicalPath()
        site_path = site.getPhysicalPath()
        nav_path = context_path[0:len(site_path) + 1]
        selected_item_path = context_path[0:len(site_path) + 2]

        #need this for the title of the nav
        self.nav_context = site.unrestrictedTraverse('/'.join(nav_path))
        #need this to find the current item
        self.selected_item = site.unrestrictedTraverse(
            '/'.join(selected_item_path))

        self.portal_tabs = buildFolderTree(context,
                                           obj=context,
                                           query={
                                               'query': '/'.join(nav_path),
                                               'navtree': 1,
                                               'navtree_start': 1,
                                               'path': '/'.join(nav_path)
                                           })

        # need to make this all one call right here for some reason,
        # otherwise it can't figure out the absolute_url
        self.nav_context_url = site.unrestrictedTraverse(
            '/'.join(nav_path)).absolute_url()
示例#56
0
 def testGetFromRootWithCurrentNavtreeAndStartLevel(self):
     context = self.portal.folder1.doc11
     query = {'path' : {'query' : '/'.join(context.getPhysicalPath()),
                        'navtree' : 1,
                        'navtree_start' : 2}}
     rootPath = '/'.join(self.portal.getPhysicalPath())
     tree = buildFolderTree(self.portal, query=query)['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')
示例#57
0
 def testGetFromRootWithNodeFilterOnFolder(self):
     class Strategy(NavtreeStrategyBase):
         def nodeFilter(self, node):
             return ('folder' not in node['item'].getId)
     tree = buildFolderTree(self.portal, strategy=Strategy())['children']
     rootPath = '/'.join(self.portal.getPhysicalPath())
     self.assertEqual(len(tree), 4)
     self.assertEqual(tree[0]['item'].getPath(), rootPath + '/doc1')
     self.assertEqual(tree[1]['item'].getPath(), rootPath + '/doc2')
     self.assertEqual(tree[2]['item'].getPath(), rootPath + '/doc3')
     self.assertEqual(tree[3]['item'].getPath(), rootPath + '/link1')
示例#58
0
    def render_tree(self):
        content = closest_content(self.context)
        source = self.bound_source

        strategy = getMultiAdapter((content, self), INavtreeStrategy)
        data = buildFolderTree(content,
                               obj=content,
                               query=source.navigation_tree_query,
                               strategy=strategy)

        return self.recurse_template(children=data.get('children', []),
                                     level=1)
 def getNavTree(self, _marker=None):
     if _marker is None:
         _marker = []
     context = aq_inner(self.context)
     queryBuilder = NavtreeQueryBuilder(self.getNavRoot())
     strategy = getMultiAdapter((context, self.data), INavtreeStrategy)
     tree = buildFolderTree(context,
                            obj=context,
                            query=queryBuilder(),
                            strategy=strategy)
     tree = self._expandFolderTree(tree, queryBuilder, strategy)
     return tree