本文整理汇总了Python中menus.menu_pool.menu_pool.apply_modifiers函数的典型用法代码示例。如果您正苦于以下问题:Python apply_modifiers函数的具体用法?Python apply_modifiers怎么用?Python apply_modifiers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apply_modifiers函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context
def get_context(self, context, levels, root_level, nephews, template):
# Django 1.4 doesn't accept 'None' as a tag value and resolve to ''
# So we need to force it to None again
if not root_level and root_level != 0:
root_level = None
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 = []
# adjust root_level so we cut before the specified level, not after
include_root = False
if root_level is not None and root_level > 0:
root_level -= 1
elif root_level is not None and root_level == 0:
include_root = True
for node in nodes:
if root_level is None:
if node.selected:
# if no root_level specified, set it to the selected nodes
# level
root_level = node.level
# is this the ancestor of current selected node at the root
# level?
is_root_ancestor = (node.ancestor and node.level == root_level)
# is a node selected on the root_level specified
root_selected = (node.selected and node.level == root_level)
if is_root_ancestor or root_selected:
cut_after(node, levels, [])
children = node.children
for child in children:
child.parent = None
if child.sibling:
cut_after(child, nephews, [])
# if root_level was 0 we need to give the menu the
# entire tree
# not just the children
if include_root:
children = menu_pool.apply_modifiers(
[node], request, post_cut=True
)
else:
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
示例2: _get_nodes
def _get_nodes(self, path='/'):
node1 = NavigationNode('1', '/1/', 1)
node2 = NavigationNode('2', '/2/', 2, 1)
node3 = NavigationNode('3', '/3/', 3, 2)
node4 = NavigationNode('4', '/4/', 4, 2)
node5 = NavigationNode('5', '/5/', 5)
nodes = [node1, node2, node3, node4, node5]
tree = _build_nodes_inner_for_one_menu([n for n in nodes], "test")
request = self.get_request(path)
menu_pool.apply_modifiers(tree, request)
return tree, nodes
示例3: show_sub_menu
def show_sub_menu(context, levels=100, template="menu/sub_menu.html"):
"""
show the sub menu of the current nav-node.
-levels: how many levels deep
-temlplate: template used to render the navigation
"""
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
示例4: get_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
示例5: _get_context_internal
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: _navigation_preview
def _navigation_preview(self, request, nav_node):
if not request or not nav_node:
return ''
nodes = menu_pool.get_nodes(request, None, None)
nodes = cut_levels(nodes, 0, 1, 1, 100)
nodes = menu_pool.apply_modifiers(
nodes, request, None, None, post_cut=True)
output = []
self._get_nodes(request, nodes, nav_node.menu_id, output)
html_preview = ''.join(output)
if 'current-node' not in html_preview:
return ""
return html_preview
示例7: show_menu
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: get_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]
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_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