Пример #1
0
    def get_context(self, context, template, namespace, root_id, offset, limit, embody_root):
        try:
            # If there's an exception (500), default context_processors may not be called.
            request = context['request']
        except KeyError:
            return {'template': 'menu/empty.html'}

        start_level = 0
        nodes = menu_pool.get_nodes(request, namespace, root_id)
        if root_id:
            # find the root id and cut the nodes
            id_nodes = menu_pool.get_nodes_by_attribute(nodes, "reverse_id", root_id)
            if id_nodes:
                node = id_nodes[0]
                nodes = node.children
                for remove_parent in nodes:
                    remove_parent.parent = None
                start_level = node.level + 1
                nodes = flatten(nodes)
                if embody_root:
                    node.level = start_level
                    nodes.insert(0, node)
            else:
                nodes = []
        children = cut_levels(nodes, start_level)
        children = menu_pool.apply_modifiers(children, request, namespace, root_id, post_cut=True)
        children = children[offset:offset + limit]
        context.update({'children': children, 'template': template})
        return context
Пример #2
0
    def get_context(self, context, template, name ):
        try:
            request = context['request']
        except KeyError:
            return { 'template': 'menu/empty.html' }
        
        all_nodes = menu_pool.get_nodes(request)
        nodes = menu_pool.get_nodes_by_attribute(all_nodes, 'type', 'family')

        for node in nodes:
            if (node.ancestor or node.selected) and node.attr['type'] == 'family':
                break
            if node.descendant: # We must be at a designer
                node.selected = True # This must be the first family, so select it
                break

        if node.selected: # We're at a family or designer, so automatically select the first stamp
          node.children[0].selected = True

        try:
            context = { 'children': node.children }
        except:
            context = { 'template': template}
            
        return context
Пример #3
0
    def get_context(self, context, template, name ):
        try:
            request = context['request']
        except KeyError:
            return { 'template': 'menu/empty.html' }
        
        all_nodes = menu_pool.get_nodes(request)
        nodes = menu_pool.get_nodes_by_attribute( all_nodes, 'type', 'designer' )

        for node in all_nodes:
            # If we're at the root level, don't bother getting children
            if node.selected and node.level < 2:
                context = { 'template': template}
                return context
        
        for node in nodes:
            if node.selected and node.attr['type'] == 'designer':
                # Set first family to be selected
                node.children[0].selected = True
                break
            if node.ancestor and node.attr['type'] == 'designer':
                break

        try:
            context = { 'children': node.children }

        except:
            context = { 'template': template}
            
        return context
Пример #4
0
    def get_context(self, context,  root_id, namespace ):
        try:
            request = context['request']
        except KeyError:
            return { 'template': 'menu/empty.html' }
        
        all_nodes = menu_pool.get_nodes(request, namespace, root_id )
        nodes = menu_pool.get_nodes_by_attribute(all_nodes, 'type', 'stamp')
        current_index = None
        
        for node in nodes:
            assert node.attr['type'] == 'stamp'

        for node in nodes:
            if node.selected or node.descendant:
                current_index = nodes.index(node)
                break

        assert current_index != None

        try:
            next_link = nodes[current_index + 1]
        except IndexError:
            next_link = ((node.parent).parent).parent
        context['next'] = next_link
        context['prev'] = None
        return context                      
Пример #5
0
    def _get_context_internal(self, context, from_level, to_level, extra_inactive,
                    extra_active, max_count, filter_opt, template, namespace, root_id, next_page):
        trim_children = (filter_opt & FILTER_TRIM_CHILDREN != 0)
        try:
            # If there's an exception (500), default context_processors may not be called.
            request = context['request']
        except KeyError:
            return {'template': 'menu/empty.html'}

        has_root_node = False

        if next_page:
            children = next_page.children
        else: 
            #new menu... get all the data so we can save a lot of queries
            nodes = menu_pool.get_nodes(request, namespace, root_id)
            if root_id: # find the root id and cut the nodes
                id_nodes = menu_pool.get_nodes_by_attribute(nodes, "reverse_id", root_id)
                if id_nodes:
                    root_node = node = id_nodes[0]
                    has_root_node = True

                    new_nodes = node.children
                    for n in new_nodes:
                        n.parent = None
                    from_level += node.level + 1
                    to_level += node.level + 1
                else:
                    new_nodes = []
                nodes = new_nodes
            children = cut_levels(nodes, from_level, to_level, extra_inactive, extra_active, trim_children)
            children = menu_pool.apply_modifiers(children, request, namespace, root_id, post_cut=True)

        if filter_opt & FILTER_INTER:
            children = [node for node in children if node.is_leaf_node]
        elif filter_opt & FILTER_LEAF:
            children = [node for node in children if not node.is_leaf_node]

        # only return the top ``max_count`` ones if specified
        if max_count != -1:
            children = children[:max_count]

        try:
            context.update({'children':children,
                            'template':template,
                            'from_level':from_level,
                            'to_level':to_level,
                            'extra_inactive':extra_inactive,
                            'extra_active':extra_active,
                            'max_count':max_count,
                            'filter_opt':filter_opt,
                            'namespace':namespace})
            if has_root_node:
                context['root_node'] = root_node

        except:
            context = {"template":template}
        return context
Пример #6
0
    def get_context(self, context, family,  root_id, namespace ):
        try:
            request = context['request']
        except KeyError:
            return { 'template': 'menu/empty.html' }
        
        # Fetch all nodes of all types
        all_nodes = menu_pool.get_nodes(request, namespace, root_id )
        # Fetch families
        nodes = menu_pool.get_nodes_by_attribute(all_nodes, 'type', 'family')

        current_index = None

        for node in nodes:
            if node.descendant:
                if node.parent.attr['type'] == 'designer' and node.parent.selected: 
                    # We're at the designer level, so make first descendant the selected node
                    current_index = nodes.index(node)
                    break
                else:
                    # We're at the root index, so just return with first family and arbitrary previoous
                    context['next'] = nodes[0]
                    context['prev'] = node.parent.parent.parent # This happens to be /resources/
                    return context
            if node.selected or node.ancestor:
                current_index = nodes.index(node)
                break

        print current_index
        assert current_index != None

        # This is done after selection, as the selected node can be invisible
        for n in nodes:
            # Cut out any invisible nodes (this could have weird behavior)
            if not n.visible:
                nodes.remove(n)
        
        try:
            next_link = nodes[current_index + 1]
        except IndexError:
            next_link = (node.parent).parent
        prev_link = nodes[current_index - 1]
        if current_index == 0:
            prev_link = (node.parent).parent


        context['next'] = next_link
        context['prev'] = prev_link

        return context                      
Пример #7
0
def show_menu(context, from_level=0, to_level=100, extra_inactive=0, extra_active=100, template="menu/menu.html", namespace=None, root_id=None, next_page=None, ):
    """
    render a nested list of all children of the pages
    - from_level: starting level
    - to_level: max level
    - extra_inactive: how many levels should be rendered of the not active tree?
    - extra_active: how deep should the children of the active node be rendered?
    - namespace: the namespace of the menu. if empty will use all namespaces
    - root_id: the id of the root node
    - template: template used to render the menu

    """
    try:
        # If there's an exception (500), default context_processors may not be called.
        request = context['request']
    except KeyError:
        return {'template': 'menu/empty.html'}
    
    if next_page:
        children = next_page.children
    else: 
        #new menu... get all the data so we can save a lot of queries
        nodes = menu_pool.get_nodes(request, namespace, root_id)
        if root_id: # find the root id and cut the nodes
            id_nodes = menu_pool.get_nodes_by_attribute(nodes, "reverse_id", root_id)
            if id_nodes:
                node = id_nodes[0]
                new_nodes = node.children
                for n in new_nodes:
                    n.parent = None
                from_level += node.level + 1
                to_level += node.level + 1
            else:
                new_nodes = []
            nodes = new_nodes
        children = cut_levels(nodes, from_level, to_level, extra_inactive, extra_active)
        children = menu_pool.apply_modifiers(children, request, namespace, root_id, post_cut=True)
    
    try:
        context.update({'children':children,
                        'template':template,
                        'from_level':from_level,
                        'to_level':to_level,
                        'extra_inactive':extra_inactive,
                        'extra_active':extra_active,
                        'namespace':namespace})
    except:
        context = {"template":template}
    return context
Пример #8
0
    def get_context(self, context, from_level, to_level, extra_inactive,
                    extra_active, template, namespace, root_id, next_page):
        try:
            # If there's an exception (500), default context_processors may not be called.
            request = context['request']
        except KeyError:
            return {'template': 'menu/empty.html'}

        if next_page:
            children = next_page.children
        else:
            # new menu... get all the data so we can save a lot of queries
            menu_renderer = context.get('cms_menu_renderer')

            if not menu_renderer:
                menu_renderer = menu_pool.get_renderer(request)

            nodes = menu_renderer.get_nodes(namespace, root_id)
            if root_id:  # find the root id and cut the nodes
                id_nodes = menu_pool.get_nodes_by_attribute(
                    nodes, "reverse_id", root_id)
                if id_nodes:
                    node = id_nodes[0]
                    nodes = node.children
                    for remove_parent in nodes:
                        remove_parent.parent = None
                    from_level += node.level + 1
                    to_level += node.level + 1
                    nodes = flatten(nodes)
                else:
                    nodes = []
            children = cut_levels(nodes, from_level, to_level, extra_inactive,
                                  extra_active)
            children = menu_renderer.apply_modifiers(children,
                                                     namespace,
                                                     root_id,
                                                     post_cut=True)

        try:
            context['children'] = children
            context['template'] = template
            context['from_level'] = from_level
            context['to_level'] = to_level
            context['extra_inactive'] = extra_inactive
            context['extra_active'] = extra_active
            context['namespace'] = namespace
        except:
            context = {"template": template}
        return context
Пример #9
0
    def get_context(self, context, template, name ):
        try:
            request = context['request']
        except KeyError:
            return { 'template': 'menu/empty.html' }
        
        nodes = menu_pool.get_nodes(request)
        nodes = menu_pool.get_nodes_by_attribute( nodes, 'type', name )

        try:
            context = { 'children': nodes }
        except:
            context = { 'template': template}
            
        return context
Пример #10
0
    def get_context(self, context, from_level, to_level, extra_inactive,
                    extra_active, template, namespace, root_id, next_page):
        try:
            # If there's an exception (500), default context_processors may not be called.
            request = context['request']
        except KeyError:
            return {'template': 'menu/empty.html'}

        if next_page:
            children = next_page.children
        else:
            #new menu... get all the data so we can save a lot of queries
            nodes = menu_pool.get_nodes(request, namespace, root_id)
            if root_id:  # find the root id and cut the nodes
                id_nodes = menu_pool.get_nodes_by_attribute(
                    nodes, "reverse_id", root_id)
                if id_nodes:
                    node = id_nodes[0]
                    new_nodes = node.children
                    for n in new_nodes:
                        n.parent = None
                    from_level += node.level + 1
                    to_level += node.level + 1
                else:
                    new_nodes = []
                nodes = new_nodes
            children = cut_levels(nodes, from_level, to_level, extra_inactive,
                                  extra_active)
            children = menu_pool.apply_modifiers(children,
                                                 request,
                                                 namespace,
                                                 root_id,
                                                 post_cut=True)

        try:
            context.update({
                'children': children,
                'template': template,
                'from_level': from_level,
                'to_level': to_level,
                'extra_inactive': extra_inactive,
                'extra_active': extra_active,
                'namespace': namespace
            })
        except:
            context = {"template": template}
        return context
Пример #11
0
    def get_context(self, context, from_level, to_level, extra_inactive,
                    extra_active, template, namespace, root_id, next_page):
        try:
            # If there's an exception (500), default context_processors may not be called.
            request = context['request']
        except KeyError:
            return {'template': 'menu/empty.html'}

        if next_page:
            children = next_page.children
        else:
            # new menu... get all the data so we can save a lot of queries
            menu_renderer = context.get('cms_menu_renderer')

            if not menu_renderer:
                menu_renderer = menu_pool.get_renderer(request)

            nodes = menu_renderer.get_nodes(namespace, root_id)
            if root_id:  # find the root id and cut the nodes
                id_nodes = menu_pool.get_nodes_by_attribute(nodes, "reverse_id", root_id)
                if id_nodes:
                    node = id_nodes[0]
                    nodes = node.children
                    for remove_parent in nodes:
                        remove_parent.parent = None
                    from_level += node.level + 1
                    to_level += node.level + 1
                    nodes = flatten(nodes)
                else:
                    nodes = []
            children = cut_levels(nodes, from_level, to_level, extra_inactive, extra_active)
            children = menu_renderer.apply_modifiers(children, namespace, root_id, post_cut=True)

        try:
            context['children'] = children
            context['template'] = template
            context['from_level'] = from_level
            context['to_level'] = to_level
            context['extra_inactive'] = extra_inactive
            context['extra_active'] = extra_active
            context['namespace'] = namespace
        except:
            context = {"template": template}
        return context
Пример #12
0
    def get_context(
        self, context, from_level, to_level, extra_inactive, extra_active, template, namespace, root_id, next_page
    ):
        try:
            # If there's an exception (500), default context_processors may not be called.
            request = context["request"]
        except KeyError:
            return {"template": "menu/empty.html"}

        if next_page:
            children = next_page.children
        else:
            # new menu... get all the data so we can save a lot of queries
            nodes = menu_pool.get_nodes(request, namespace, root_id)
            if root_id:  # find the root id and cut the nodes
                id_nodes = menu_pool.get_nodes_by_attribute(nodes, "reverse_id", root_id)
                if id_nodes:
                    node = id_nodes[0]
                    new_nodes = node.children
                    for n in new_nodes:
                        n.parent = None
                    from_level += node.level + 1
                    to_level += node.level + 1
                else:
                    new_nodes = []
                nodes = new_nodes
            children = cut_levels(nodes, from_level, to_level, extra_inactive, extra_active)
            children = menu_pool.apply_modifiers(children, request, namespace, root_id, post_cut=True)

        try:
            context.update(
                {
                    "children": children,
                    "template": template,
                    "from_level": from_level,
                    "to_level": to_level,
                    "extra_inactive": extra_inactive,
                    "extra_active": extra_active,
                    "namespace": namespace,
                }
            )
        except:
            context = {"template": template}
        return context
Пример #13
0
    def get_context(self, context, template, name ):
        try:
            request = context['request']
        except KeyError:
            return { 'template': 'menu/empty.html' }
        
        all_nodes = menu_pool.get_nodes(request)
        nodes = menu_pool.get_nodes_by_attribute( all_nodes, 'type', 'designer' )
        
        for node in nodes:
            if (node.ancestor or node.selected):
                node.selected = True # make sure this is true, as we'll use it in the templates
                break

        try:
            context = { 'children': nodes }
        except:
            context = { 'template': template}
            
        return context
Пример #14
0
def show_menu(
    context,
    from_level=0,
    to_level=100,
    extra_inactive=0,
    extra_active=100,
    template="menu/menu.html",
    namespace=None,
    root_id=None,
    next_page=None,
):
    """
    render a nested list of all children of the pages
    - from_level: starting level
    - to_level: max level
    - extra_inactive: how many levels should be rendered of the not active tree?
    - extra_active: how deep should the children of the active node be rendered?
    - namespace: the namespace of the menu. if empty will use all namespaces
    - root_id: the id of the root node
    - template: template used to render the menu

    """
    try:
        # If there's an exception (500), default context_processors may not be called.
        request = context['request']
    except KeyError:
        return {'template': 'menu/empty.html'}

    if next_page:
        children = next_page.children
    else:
        #new menu... get all the data so we can save a lot of queries
        nodes = menu_pool.get_nodes(request, namespace, root_id)
        if root_id:  # find the root id and cut the nodes
            id_nodes = menu_pool.get_nodes_by_attribute(
                nodes, "reverse_id", root_id)
            if id_nodes:
                node = id_nodes[0]
                new_nodes = node.children
                for n in new_nodes:
                    n.parent = None
                from_level += node.level + 1
                to_level += node.level + 1
            else:
                new_nodes = []
            nodes = new_nodes
        children = cut_levels(nodes, from_level, to_level, extra_inactive,
                              extra_active)
        children = menu_pool.apply_modifiers(children,
                                             request,
                                             namespace,
                                             root_id,
                                             post_cut=True)

    try:
        context.update({
            'children': children,
            'template': template,
            'from_level': from_level,
            'to_level': to_level,
            'extra_inactive': extra_inactive,
            'extra_active': extra_active,
            'namespace': namespace
        })
    except:
        context = {"template": template}
    return context