def get_context(self, context, levels, template): try: # If there's an exception (500), default context_processors may not be called. request = context['request'] except KeyError: return {'template': 'menu/empty.html'} nodes = menu_pool.get_nodes(request) children = [] for node in nodes: if node.selected: cut_after(node, levels, []) children = node.children for child in children: child.parent = None children = menu_pool.apply_modifiers(children, request, post_cut=True) context.update({ 'children': children, 'template': template, 'from_level': 0, 'to_level': 0, 'extra_inactive': 0, 'extra_active': 0 }) return context
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
def get_context(self, context, start_level, template, only_visible): try: # If there's an exception (500), default context_processors may not be called. request = context['request'] except KeyError: return {'template': 'cms/content.html'} if not (isinstance(start_level, int) or start_level.isdigit()): only_visible = template template = start_level start_level = 0 try: only_visible = bool(int(only_visible)) except: only_visible = bool(only_visible) ancestors = [] nodes = menu_pool.get_nodes(request, breadcrumb=True) selected = None home = None for node in nodes: if node.selected: selected = node if node.get_absolute_url() == urllib.unquote( reverse("pages-root")): home = node if selected and selected != home: n = selected while n: if n.visible or not only_visible: ancestors.append(n) n = n.parent if not ancestors or (ancestors and ancestors[-1] != home) and home: ancestors.append(home) ancestors.reverse() if len(ancestors) >= start_level: ancestors = ancestors[start_level:] else: ancestors = [] context.update({'ancestors': ancestors, 'template': template}) return context
def get_context(self, context, start_level, template, only_visible): try: # If there's an exception (500), default context_processors may not be called. request = context['request'] except KeyError: return {'template': 'cms/content.html'} if not (isinstance(start_level, int) or start_level.isdigit()): only_visible = template template = start_level start_level = 0 try: only_visible = bool(int(only_visible)) except: only_visible = bool(only_visible) ancestors = [] nodes = menu_pool.get_nodes(request, breadcrumb=True) selected = None home = None for node in nodes: if node.selected: selected = node if node.get_absolute_url() == urllib.unquote(reverse("pages-root")): home = node if selected and selected != home: n = selected while n: if n.visible or not only_visible: ancestors.append(n) n = n.parent if not ancestors or (ancestors and ancestors[-1] != home) and home: ancestors.append(home) ancestors.reverse() if len(ancestors) >= start_level: ancestors = ancestors[start_level:] else: ancestors = [] context.update({'ancestors':ancestors, 'template': template}) return context
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
def get_context(self, context, levels, template): try: # If there's an exception (500), default context_processors may not be called. request = context['request'] except KeyError: return {'template': 'menu/empty.html'} nodes = menu_pool.get_nodes(request) children = [] for node in nodes: if node.selected: cut_after(node, levels, []) children = node.children for child in children: child.parent = None children = menu_pool.apply_modifiers(children, request, post_cut=True) context.update({ 'children':children, 'template':template, 'from_level':0, 'to_level':0, 'extra_inactive':0, 'extra_active':0 }) return context