예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
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
예제 #5
0
def query_items(root, path, query={}):
    """
    Return a navtree of portal_catalog queried items in their natural order.

    @param path: INavigationRoot content object

    @param path: Path relative to INavigationRoot to set the query path

    @param query: Dictionary of portal_catalog query parameters

    @return: Navtree dictionary

    @raises: KeyError if path is not available
    """
    # Apply default search filters
    absolute_path = '/'.join(root.getPhysicalPath() + (path.strip('/'),))
    applied_query = {
        'sort_on': 'getObjPositionInParent'
    }
    # Apply caller's filters
    applied_query.update(query)
    # Set the navigation tree build strategy
    strategy = DefaultNavtreeStrategy(root)
    strategy.rootPath = absolute_path
    strategy.showAllParents = False
    # This will yield out tree of nested dicts of item brains
    navtree = buildFolderTree(root, root, applied_query, strategy=strategy)

    def cleanup(child):
        """ Recursively cleanup the tree """
        children = child.get('children', [])
        for childchild in children:
            cleanup(childchild)
        cleaned = {u'title': child['Title'], u'name': child['id'],
                   u'children': children}
        child.clear()
        child.update(cleaned)

    if "id" in navtree:
        cleanup(navtree)
    else:
        raise KeyError
    return navtree
예제 #6
0
파일: navbar.py 프로젝트: a25kk/hfph
 def siteNavStrategy(self):
     context = aq_inner(self.context)
     root = getNavigationRoot(context)
     selected_tab = self.selected_portal_tab
     obj = api.portal.get()[selected_tab]
     path = {'query': '/'.join(obj.getPhysicalPath()),
             'navtree': 1,
             'navtree_start': 1,
             'depth': 3}
     query = {
         'path': path,
         'review_state': 'published',
         'portal_type': ('hph.sitecontent.mainsection',
                         'hph.sitecontent.contentpage',
                         'hph.lectures.coursefolder'),
         '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(query)
     items = []
     for c in tree['children']:
         item = {}
         item['item'] = c['item']
         item['children'] = c.get('children', '')
         item_id = c['item'].getId
         if item_id == context.getId():
             item['class'] = 'active'
         else:
             item['class'] = ''
         item['itemid'] = item_id
         items.append(item)
     return tree
예제 #7
0
 def nodeFilter(self, node):
     """ Filter node
     """
     if not getattr(node['item'], 'is_folderish', False):
         return False
     return DefaultNavtreeStrategy.nodeFilter(self, node)
예제 #8
0
 def __init__(self, context, view=None):
     DefaultNavtreeStrategy.__init__(self, context, view)
     self.rootPath = '/'.join(getApplicationRoot(context).getPhysicalPath())
예제 #9
0
 def nodeFilter(self, node):
     """ Filter node
     """
     if not getattr(node['item'], 'is_folderish', False):
         return False
     return DefaultNavtreeStrategy.nodeFilter(self, node)
예제 #10
0
 def __init__(self, context, view=None):
     DefaultNavtreeStrategy.__init__(self, context, view)
     self.rootPath = '/'.join(getApplicationRoot(context).getPhysicalPath())