sitetree/sitetreeapp.py
def menu(self, tree_alias, tree_branches, context):
        """Builds and returns menu structure for 'sitetree_menu' tag.

        :param str|unicode tree_alias:
        :param str|unicode tree_branches:
        :param Context context:
        :rtype: list|str
        """
        tree_alias, sitetree_items = self.init_tree(tree_alias, context)

        if not sitetree_items:
            return ''

        tree_branches = self.resolve_var(tree_branches)

        parent_isnull = False
        parent_ids = []
        parent_aliases = []

        current_item = self.get_tree_current_item(tree_alias)
        self.tree_climber(tree_alias, current_item)

        # Support item addressing both through identifiers and aliases.
        for branch_id in tree_branches.split(','):
            branch_id = branch_id.strip()

            if branch_id == ALIAS_TRUNK:
                parent_isnull = True

            elif branch_id == ALIAS_THIS_CHILDREN and current_item is not None:
                branch_id = current_item.id
                parent_ids.append(branch_id)

            elif branch_id == ALIAS_THIS_ANCESTOR_CHILDREN and current_item is not None:
                branch_id = self.get_ancestor_item(tree_alias, current_item).id
                parent_ids.append(branch_id)

            elif branch_id == ALIAS_THIS_SIBLINGS and current_item is not None and current_item.parent is not None:
                branch_id = current_item.parent.id
                parent_ids.append(branch_id)

            elif branch_id == ALIAS_THIS_PARENT_SIBLINGS and current_item is not None:
                branch_id = self.get_ancestor_level(current_item, depth=2).id
                parent_ids.append(branch_id)

            elif branch_id.isdigit():
                parent_ids.append(int(branch_id))

            else:
                parent_aliases.append(branch_id)

        check_access = self.check_access

        menu_items = []
        for item in sitetree_items:
            if not item.hidden and item.inmenu and check_access(item, context):
                if item.parent is None:
                    if parent_isnull:
                        menu_items.append(item)
                else:
                    if item.parent.id in parent_ids or item.parent.alias in parent_aliases:
                        menu_items.append(item)

        menu_items = self.apply_hook(menu_items, 'menu')
        self.update_has_children(tree_alias, menu_items, 'menu')
        return menu_items
def menu(self, tree_alias, tree_branches, context):
        tree_alias, sitetree_items = self.init_tree(tree_alias, context)

        if not sitetree_items:
            return ''

        tree_branches = self.resolve_var(tree_branches)

        parent_isnull = False
        parent_ids = []
        parent_aliases = []

        current_item = self.get_tree_current_item(tree_alias)
        self.tree_climber(tree_alias, current_item)

        # Support item addressing both through identifiers and aliases.
        for branch_id in tree_branches.split(','):
            branch_id = branch_id.strip()

            if branch_id == ALIAS_TRUNK:
                parent_isnull = True

            elif branch_id == ALIAS_THIS_CHILDREN and current_item is not None:
                branch_id = current_item.id
                parent_ids.append(branch_id)

            elif branch_id == ALIAS_THIS_ANCESTOR_CHILDREN and current_item is not None:
                branch_id = self.get_ancestor_item(tree_alias, current_item).id
                parent_ids.append(branch_id)

            elif branch_id == ALIAS_THIS_SIBLINGS and current_item is not None and current_item.parent is not None:
                branch_id = current_item.parent.id
                parent_ids.append(branch_id)

            elif branch_id == ALIAS_THIS_PARENT_SIBLINGS and current_item is not None:
                branch_id = self.get_ancestor_level(current_item, depth=2).id
                parent_ids.append(branch_id)

            elif branch_id.isdigit():
                parent_ids.append(int(branch_id))

            else:
                parent_aliases.append(branch_id)

        check_access = self.check_access

        menu_items = []
        for item in sitetree_items:
            if not item.hidden and item.inmenu and check_access(item, context):
                if item.parent is None:
                    if parent_isnull:
                        menu_items.append(item)
                else:
                    if item.parent.id in parent_ids or item.parent.alias in parent_aliases:
                        menu_items.append(item)

        menu_items = self.apply_hook(menu_items, 'menu')
        self.update_has_children(tree_alias, menu_items, 'menu')
        return menu_items
def menu ( self , tree_alias , tree_branches , context ) : tree_alias , sitetree_items = self . init_tree ( tree_alias , context ) if not sitetree_items : return '' tree_branches = self . resolve_var ( tree_branches ) parent_isnull = False parent_ids = [ ] parent_aliases = [ ] current_item = self . get_tree_current_item ( tree_alias ) self . tree_climber ( tree_alias , current_item ) # Support item addressing both through identifiers and aliases. for branch_id in tree_branches . split ( ',' ) : branch_id = branch_id . strip ( ) if branch_id == ALIAS_TRUNK : parent_isnull = True elif branch_id == ALIAS_THIS_CHILDREN and current_item is not None : branch_id = current_item . id parent_ids . append ( branch_id ) elif branch_id == ALIAS_THIS_ANCESTOR_CHILDREN and current_item is not None : branch_id = self . get_ancestor_item ( tree_alias , current_item ) . id parent_ids . append ( branch_id ) elif branch_id == ALIAS_THIS_SIBLINGS and current_item is not None and current_item . parent is not None : branch_id = current_item . parent . id parent_ids . append ( branch_id ) elif branch_id == ALIAS_THIS_PARENT_SIBLINGS and current_item is not None : branch_id = self . get_ancestor_level ( current_item , depth = 2 ) . id parent_ids . append ( branch_id ) elif branch_id . isdigit ( ) : parent_ids . append ( int ( branch_id ) ) else : parent_aliases . append ( branch_id ) check_access = self . check_access menu_items = [ ] for item in sitetree_items : if not item . hidden and item . inmenu and check_access ( item , context ) : if item . parent is None : if parent_isnull : menu_items . append ( item ) else : if item . parent . id in parent_ids or item . parent . alias in parent_aliases : menu_items . append ( item ) menu_items = self . apply_hook ( menu_items , 'menu' ) self . update_has_children ( tree_alias , menu_items , 'menu' ) return menu_items
Builds and returns menu structure for 'sitetree_menu' tag.

        :param str|unicode tree_alias:
        :param str|unicode tree_branches:
        :param Context context:
        :rtype: list|str
Builds and returns menu structure for sitetree_menu tag .