class MainMenu(InclusionTag): name = 'main_menu' template = 'menu/dummy.html' options = Options( StringArgument( 'template', default='bootstrap{}/menu/navbar.html'.format(BOOTSTRAP), required=False), StringArgument('namespace', default=None, required=False), StringArgument('root_id', default=None, required=False), IntegerArgument('offset', default=0, required=False), IntegerArgument('limit', default=100, required=False), Flag('embody_root', default=False, true_values=['embody_root']), Argument('next_page', default=None, required=False), ) def get_context(self, context, template, namespace, root_id, offset, limit, embody_root, 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'} start_level = 0 if next_page: children = next_page.children else: 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 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_renderer.apply_modifiers(children, namespace, root_id, post_cut=True) children = children[offset:offset + limit] context.update({'children': children, 'template': template}) return context
class MainMenuBelowId(MainMenu): name = 'main_menu_below_id' options = Options( Argument('root_id', default=None, required=False), StringArgument('template', default='bootstrap/menu/navbar.html', required=False), IntegerArgument('offset', default=0, required=False), IntegerArgument('limit', default=100, required=False), StringArgument('namespace', default=None, required=False), Flag('embody_root', default=False, true_values=['embody_root']), )
class MainMenuEmbodyId(MainMenu): name = 'main_menu_embody_id' options = Options( Argument('root_id', default=None, required=False), StringArgument('template', default='bootstrap/menu/navbar.html', required=False), StringArgument('namespace', default=None, required=False), Flag('embody_root', default=True, false_values=['skip_root']), )
class MainMenuEmbodyId(MainMenu): name = 'main_menu_embody_id' options = Options( Argument('root_id', default=None, required=False), StringArgument('template', default='bootstrap{}/menu/navbar.html'.format(BOOTSTRAP), required=False), IntegerArgument('offset', default=0, required=False), IntegerArgument('limit', default=100, required=False), StringArgument('namespace', default=None, required=False), Flag('embody_root', default=True, false_values=['skip_root']), Argument('next_page', default=None, required=False), )
class Addtoblock(SekizaiTag): name = 'addtoblock' options = Options( Argument('name'), Flag('strip', default=False, true_values=['strip']), parser_class=AddtoblockParser, ) def render_tag(self, context, name, strip, nodelist): rendered_contents = nodelist.render(context) if strip: rendered_contents = rendered_contents.strip() varname = get_varname() context[varname][name].append(rendered_contents) return ""
class MainMenu(InclusionTag): name = 'main_menu' template = 'menu/dummy.html' options = Options( StringArgument('template', default='bootstrap/menu/navbar.html', required=False), StringArgument('namespace', default=None, required=False), StringArgument('root_id', default=None, required=False), Flag('embody_root', default=False, true_values=['embody_root']), ) def get_context(self, context, template, namespace, root_id, 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) context.update({'children': children, 'template': template}) return context
class Addtoblock(SekizaiTag): name = 'addtoblock' options = Options( Argument('name'), Flag('strip', default=False, true_values=['strip']), 'preprocessor', Argument('preprocessor', required=False, default=None, resolve=False), parser_class=AddtoblockParser, ) def render_tag(self, context, name, strip, preprocessor, nodelist): rendered_contents = nodelist.render(context) if strip: rendered_contents = rendered_contents.strip() if preprocessor: func = import_processor(preprocessor) rendered_contents = func(context, rendered_contents, name) varname = get_varname() context[varname][name].append(rendered_contents) return ""