本文整理汇总了Python中menus.menu_pool.menu_pool.register_modifier函数的典型用法代码示例。如果您正苦于以下问题:Python register_modifier函数的具体用法?Python register_modifier怎么用?Python register_modifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_modifier函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.simple_user = User.objects.create(username='simple_user', email='[email protected]',
password='simple_user')
self.advanced_user = User.objects.create(username='advanced_user', email='[email protected]',
password='advanced_user')
self.superuser = User.objects.create(username='super_user', email='[email protected]',
password='super_user', is_superuser=True)
self.advanced_group = Group.objects.create(name='advanced_group')
self.advanced_group.user_set.add(self.advanced_user)
page_defaults = {
'template': 'menu_test.html',
'language': 'en-us',
}
with self.settings(CMS_PERMISSION=False):
self.p1 = create_page('P1', published=True, in_navigation=True, **page_defaults)
self.p2 = create_page('P2', published=True, in_navigation=True, parent=self.p1, **page_defaults)
self.p3 = create_page('P3', published=True, in_navigation=True, parent=self.p2, **page_defaults)
self.p4 = create_page('P4', published=True, in_navigation=True, **page_defaults)
self.p5 = create_page('P5', published=True, in_navigation=True, parent=self.p4, **page_defaults)
self.p6 = create_page('P6', published=True, in_navigation=False, **page_defaults)
self.p7 = create_page('P7', published=True, in_navigation=True, parent=self.p6, **page_defaults)
self.p8 = create_page('P8', published=True, in_navigation=True, parent=self.p6, **page_defaults)
p1_action = CMSAction.objects.create(name='p1_action', page=self.p1.publisher_public)
p1_action.users.add(self.simple_user)
p1_action.groups.add(self.advanced_group)
p2_action = CMSAction.objects.create(name='p2_action', page=self.p2.publisher_public)
p2_action.users.add(self.simple_user)
p3_action = CMSAction.objects.create(name='p3_action', page=self.p3.publisher_public)
p4_action = CMSAction.objects.create(name='p4_action', page=self.p4.publisher_public)
p4_action.users.add(self.simple_user)
p4_action.groups.add(self.advanced_group)
p5_action = CMSAction.objects.create(name='p5_action', page=self.p5.publisher_public)
p5_action.groups.add(self.advanced_group)
p6_action = CMSAction.objects.create(name='p6_action', page=self.p6.publisher_public)
p6_action.groups.add(self.advanced_group)
p7_action = CMSAction.objects.create(name='p7_action', page=self.p7.publisher_public)
p7_action.users.add(self.simple_user)
p8_action = CMSAction.objects.create(name='p8_action', page=self.p8.publisher_public)
p8_action.groups.add(self.advanced_group)
menu_pool.register_modifier(ACLModifier)
示例2: register
def register():
menu_pool.register_modifier(Marker)
menu_pool.register_modifier(AuthVisibility)
menu_pool.register_modifier(Level)
if settings.CMS_GROUPS_RESTRICTED \
and settings.CMS_GROUPS_RESTRICTED_NAVIGATION:
menu_pool.register_modifier(GroupVisibility)
示例3: reverse
nodes = []
nodes.append(NavigationNode(_('Tags'), reverse('objectapp_tag_list'),
'tags'))
for tag in tags_published():
nodes.append(NavigationNode(tag.name,
reverse('objectapp_tag_detail',
args=[tag.name]),
tag.pk, 'tags'))
return nodes
class GbobjectModifier(Modifier):
"""Menu Modifier for gbobjects,
hide the MenuGbobject in navigation, not in breadcrumbs"""
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
"""Modify nodes of a menu"""
if breadcrumb:
return nodes
for node in nodes:
if node.attr.get('hidden'):
nodes.remove(node)
return nodes
menu_pool.register_menu(GbobjectMenu)
menu_pool.register_menu(ObjecttypeMenu)
menu_pool.register_menu(AuthorMenu)
menu_pool.register_menu(TagMenu)
menu_pool.register_modifier(GbobjectModifier)
示例4: modify
Then attempt to set icons referenced to page id.
"""
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
# import ipdb; ipdb.set_trace()
# if post_cut:
# return nodes
# if breadcrumb:
# return nodes
for node in nodes:
try:
# Load Menu Icons into template tags
if __version__ >= "2.4" and __version__ < "3": # tested with django-cms at version 2.4.3
# Load Menu Icons into template tags
# Workaround due to the double publishing feature added in 2.4.
# menu icons refers to page marked as "publisher_is_draft"
node_page = Page.objects.get( id = node.id )
draft_page_id = node_page.id if node_page.publisher_is_draft else node_page.publisher_public_id
menu_icons = MenuIcon.objects.get( page = draft_page_id )
else:
menu_icons = MenuIcon.objects.get(page=(node.id))
node.menu_icon_image = menu_icons.menu_icon_image
node.menu_icon_url = menu_icons.menu_icon_url
node.menu_icon_font_awesome = menu_icons.menu_icon_font_awesome
except:
pass
return nodes
menu_pool.register_modifier(MenuIconsMod)
示例5: len
insert_at = position if position < len(nodes) else len(nodes) - 1
for node in nodes:
# Discover nodes in the explore menu and separate them
if node.id == id:
matched_node = node
matched_children.append(node)
elif matched_node in node.get_ancestors():
matched_children.append(node)
else:
modified_nodes.append(node)
# Add the explore nodes back at the specified position
for node in matched_children:
modified_nodes.insert(insert_at, node)
insert_at += 1
return modified_nodes
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
if post_cut:
return nodes
modified_nodes = self.move_node(nodes, 'explore',
plugin_settings.STORYBASE_EXPLORE_MENU_POSITION)
modified_nodes = self.move_node(modified_nodes, 'build',
plugin_settings.STORYBASE_BUILD_MENU_POSITION)
return modified_nodes
menu_pool.register_modifier(OrderMenuNodes)
示例6: hasattr
if node.attr.get("is_home", False) and not node.visible:
extnode.parent_id = None
extnode.parent_namespace = None
extnode.parent = None
else:
extnode.parent_id = node.id
extnode.parent_namespace = node.namespace
extnode.parent = node
node.children.append(extnode)
removed = []
# find all not assigned nodes
for menu in menu_pool.menus.items():
if hasattr(menu[1], 'cms_enabled') and menu[1].cms_enabled and not menu[0] in exts:
for node in nodes:
if node.namespace == menu[0]:
removed.append(node)
if breadcrumb:
# if breadcrumb and home not in navigation add node
if breadcrumb and home and not home.visible:
home.visible = True
if request.path == home.get_absolute_url():
home.selected = True
else:
home.selected = False
# remove all nodes that are nav_extenders and not assigned
for node in removed:
nodes.remove(node)
return nodes
menu_pool.register_modifier(NavExtender)
示例7: SoftRootCutter
for node in nodes:
if node.namespace == menu[0]:
removed.append(node)
if breadcrumb:
# if breadcrumb and home not in navigation add node
if breadcrumb and home and not home.visible:
home.visible = True
if request.path == home.get_absolute_url():
home.selected = True
else:
home.selected = False
# remove all nodes that are nav_extenders and not assigned
for node in removed:
nodes.remove(node)
return nodes
menu_pool.register_modifier(NavExtender)
class SoftRootCutter(Modifier):
"""
If anyone understands this, PLEASE write a meaningful description here!
"""
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
# only apply this modifier if we're pre-cut (since what we do is cut)
if post_cut or not settings.CMS_SOFTROOT:
return nodes
selected = None
root_nodes = []
# find the selected node as well as all the root nodes
for node in nodes:
if node.selected:
示例8: objects
from cms.cms_menus import CMSMenu
from cms.models import Page
from menus.base import Modifier
from menus.menu_pool import menu_pool
# Menu nodes which represent real CMS Page objects (vs. some node
# synthesized by a CMS app, such as a "page" for items in a FAQ
# category) have this namespace.
CMS_PAGE_NODE_NAMESPACE = CMSMenu.__name__
class AddIconNameExtension(Modifier):
"""Make the IconNameExtension available in the menu."""
def _modify_nodes(self, nodes):
for node in nodes:
if node.namespace == CMS_PAGE_NODE_NAMESPACE:
page = Page.objects.get(pk=node.id)
if getattr(page, 'iconnameextension', None):
setattr(node, 'iconnameextension', page.iconnameextension)
self._modify_nodes(node.children)
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
if post_cut and not breadcrumb:
self._modify_nodes(nodes)
return nodes
menu_pool.register_modifier(AddIconNameExtension)
示例9: NewsCleaner
pub.strftime('year_%Y_month_%m_day_%d')))
return nodes
menu_pool.register_menu(NewsyMenu)
class NewsCleaner(Modifier):
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
if post_cut or breadcrumb:
return nodes
tags = 0
filter_dates = re.compile(r'^year_\d{4}_month_\d{1,2}(_day_\d{1,2})?$')
for node in nodes:
if node.namespace != 'NewsyMenu':
continue
if node.parent_id == 'tags':
tags += 1
if tags > 5:
node.visible = False
continue
if filter_dates.match(str(node.parent_id)):
node.visible = False
return nodes
menu_pool.register_modifier(NewsCleaner)
示例10: resolve
"""
if self.in_blog_menu_tree(node):
func, args, kwargs = resolve(request.path)
if self.is_blog_entry(kwargs):
"""
Then try to match the blog category nav node
with the the primary category of the blog entry
"""
entry_categories = kwargs['queryset'][0].categories.all()
if len(entry_categories) > 0:
primary_category = entry_categories[0]
if node.title.lower() == primary_category.slug.lower():
node.selected = True
else:
if self.is_top_level_blog_node(node):
node.selected = True
else:
if 'categories' not in request.path \
and self.is_top_level_blog_node(node):
"""
If they're looking at a tag, author or some other blog
related thing that is not part of blog sub navigation
bar and is not an entry just make sure 'blog' lights up
"""
node.selected = True
return nodes
menu_pool.register_menu(FlatBlogCategoryMenu)
menu_pool.register_modifier(FlatBlogCategoryModifier)
示例11: FollowModifier
menu_pool.register_menu(NewsMenu)
class FollowModifier(Modifier):
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
if not post_cut:
return nodes
appNodes = [node for node in nodes if 'targetIndex' in node.attr]
cmsNodes = [node for node in nodes if not 'targetIndex' in node.attr]
resultNodes = []
appNodeIndex = 0
cmsNodeIndex = 0
for resultNodeIndex in range(len(nodes)):
if appNodeIndex < len(appNodes) and appNodes[appNodeIndex].attr['targetIndex'] == resultNodeIndex:
resultNodes.append(appNodes[appNodeIndex])
appNodeIndex += 1
elif cmsNodeIndex < len(cmsNodes):
resultNodes.append(cmsNodes[cmsNodeIndex])
cmsNodeIndex += 1
else:
raise Exception('Error merging app menu and cms menu items')
return resultNodes
menu_pool.register_modifier(FollowModifier)
示例12: TheselectionMode
from menus.base import Modifier
from menus.menu_pool import menu_pool
from cms.models import Page
class TheselectionMode(Modifier):
"""
"""
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
extension = Page.theselectionextension
for node in nodes:
try:
page = Page.objects.get(pk=node.id)
extensions = page.theselectionextension
node.subtitle = extensions.subtitle
node.backgroundcolor = extensions.backgroundcolor
except:
pass
return nodes
menu_pool.register_modifier(TheselectionMode)
示例13: reverse
nodes = []
nodes.append(NavigationNode(_('Tags'), reverse('gstudio_tag_list'),
'tags'))
for tag in tags_published():
nodes.append(NavigationNode(tag.name,
reverse('gstudio_tag_detail',
args=[tag.name]),
tag.pk, 'tags'))
return nodes
class ObjecttypeModifier(Modifier):
"""Menu Modifier for objecttypes,
hide the MenuObjecttype in navigation, not in breadcrumbs"""
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
"""Modify nodes of a menu"""
if breadcrumb:
return nodes
for node in nodes:
if node.attr.get('hidden'):
nodes.remove(node)
return nodes
menu_pool.register_menu(ObjecttypeMenu)
menu_pool.register_menu(MetatypeMenu)
menu_pool.register_menu(AuthorMenu)
menu_pool.register_menu(TagMenu)
menu_pool.register_modifier(ObjecttypeModifier)
示例14: next
root_page = visible_roots.get(root_blog_node.position)
if root_page:
# insert at exact position
position_in_nodes = nodes_with_position[root_page]
elif last_node:
# insert after last visible
position_in_nodes = nodes_with_position[last_node] + 1
nodes.insert(position_in_nodes, blog_nav_node)
new_nodes.append(blog_nav_node)
# add all blog nodes that are children of other blog nodes
for b_id in parents_with_children.keys():
parent_blog_node = next(
ifilter(lambda n: n.id == b_id, new_nodes), None)
if not parent_blog_node:
continue
for blog_node in parents_with_children.pop(parent_blog_node.id):
blog_nav_node = _make_navigation_node(
blog_node, parent_blog_node, proxy_prefix, node_visible)
parent_blog_node.children.insert(
blog_node.position, blog_nav_node)
new_nodes.append(blog_nav_node)
menu_pool._mark_selected(request, new_nodes)
return nodes
menu_pool.register_modifier(BlogNavigationExtender)
示例15: MenuPost
from contents.models import Post
from menus.base import Modifier
from menus.menu_pool import menu_pool
class MenuPost(Modifier):
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
if post_cut:
return nodes
for node in nodes:
node.attr['posts'] = Post.objects.language().filter(translations__active=True, pages_id=node.id).order_by('-date').distinct()
return nodes
menu_pool.register_modifier(MenuPost)