def setUp(self): self.simple_user = User.objects.create(username='******', email='*****@*****.**', password='******') self.advanced_user = User.objects.create(username='******', email='*****@*****.**', password='******') self.superuser = User.objects.create(username='******', email='*****@*****.**', password='******', 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)
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)
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)
def register(): menu_pool.register_modifier(Marker) menu_pool.register_modifier(AuthVisibility) menu_pool.register_modifier(Level)
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)
from menus.base import Modifier from menus.menu_pool import menu_pool class GlobalMenuModifier(Modifier): """ If the user is logged in, remove certain menu options. Django cms provides a way to hide an option from a non logged in user, but no way to hide something from someone who is logged in. This menu modifier adds this capability. """ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): # We don't modify the breadcrumb, and we also wait until the post_cut # phase so that we process a potentially smaller node tree. # See http://www.3lance.lv/django-cms/app_integration.html if breadcrumb or not post_cut or not request.user.is_authenticated(): return nodes trim_nodes = ['/login/', '/register/'] return filter(lambda node: node.url not in trim_nodes, nodes) menu_pool.register_modifier(GlobalMenuModifier)
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)
def ready(): from menus.base import Modifier from menus.menu_pool import menu_pool class SelectedModifier(Modifier): """ This modifier is designed so that if a parent node and a descendant of a node point to the same URL, then the deepest descendant that point to the URL is the one that is going to be selected. The default behavior of Django CMS is to select the first node that matches a URL. Note that this code probably won't behave well if siblings match the same URL. """ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): sels = [node for node in nodes if node.selected] # # This block is here only to deal with this issue: # # https://github.com/divio/django-cms/issues/4118 # # and should be removed when the issue is fixed. # if not sels: # We do not mess with ancestor, descendant, etc. because # a) these have not been set yet, and b) they will be set # later. sel = None for node in nodes: node.selected = False if request.path.startswith(node.get_absolute_url()) and \ (not sel or len(node.get_absolute_url()) > len( sel.get_absolute_url())): sel = node if sel: sel.selected = True # End of the block to remove when the issue is fixed. for sel in sels: url = sel.get_absolute_url() # All descendants of the node that match the url are # preliminary candidates. preliminary = [x for x in sel.get_descendants() if x.get_absolute_url() == url] # Those that have any descendant among our preliminary set are # excluded. candidates = [x for x in preliminary if not any([d for d in x.get_descendants() if d in preliminary])] if candidates: sel.selected = False candidates[0].selected = True return nodes import cms.cms_menus menu_pool.register_modifier(SelectedModifier) # # Override the default admin site so that all apps will register # their administration interfaces to the "full-admin" site. The # only people who can access the full-admin site are superusers. # # To allow staff to edit Django CMS pages, the Django CMS admin # models are registered to a limited site which sits at the usual # admin URL. # from django.contrib import admin from django.contrib.admin import sites class FullAdminSite(admin.AdminSite): def has_permission(self, request): return request.user.is_superuser mysite = FullAdminSite("full-admin") admin.site = mysite sites.site = mysite
from menus.base import Menu, NavigationNode, Modifier from menus.menu_pool import menu_pool from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse class CoreMenu(Menu): def get_nodes(self, request): nodes = [] compare = NavigationNode(_('compare'), reverse('compare'), 1, attr={'priority':1002}) candidates = NavigationNode(_('candidates'), reverse('candidates'), 2, attr={'priority':1001}) partners = NavigationNode(_('partners'), reverse('partners'), 2, attr={'priority':1003}) nodes.append(candidates) nodes.append(compare) nodes.append(partners) return nodes class CoreModifier(Modifier): def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): return sorted( nodes, key=lambda n: n.attr.get('priority', 1000) ) menu_pool.register_menu(CoreMenu) menu_pool.register_modifier(CoreModifier)
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)
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)
def ready(): from menus.base import Modifier from menus.menu_pool import menu_pool class SelectedModifier(Modifier): """ This modifier is designed so that if a parent node and a descendant of a node point to the same URL, then the deepest descendant that point to the URL is the one that is going to be selected. The default behavior of Django CMS is to select the first node that matches a URL. Note that this code probably won't behave well if siblings match the same URL. """ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): sels = [node for node in nodes if node.selected] # # This block is here only to deal with this issue: # # https://github.com/divio/django-cms/issues/4118 # # and should be removed when the issue is fixed. # if not sels: # We do not mess with ancestor, descendant, etc. because # a) these have not been set yet, and b) they will be set # later. sel = None for node in nodes: node.selected = False if request.path.startswith(node.get_absolute_url()) and \ (not sel or len(node.get_absolute_url()) > len( sel.get_absolute_url())): sel = node if sel: sel.selected = True # End of the block to remove when the issue is fixed. for sel in sels: url = sel.get_absolute_url() # All descendants of the node that match the url are # preliminary candidates. preliminary = [ x for x in sel.get_descendants() if x.get_absolute_url() == url ] # Those that have any descendant among our preliminary set are # excluded. candidates = [ x for x in preliminary if not any( [d for d in x.get_descendants() if d in preliminary]) ] if candidates: sel.selected = False candidates[0].selected = True return nodes import cms.cms_menus menu_pool.register_modifier(SelectedModifier) # # Override the default admin site so that all apps will register # their administration interfaces to the "full-admin" site. The # only people who can access the full-admin site are superusers. # # To allow staff to edit Django CMS pages, the Django CMS admin # models are registered to a limited site which sits at the usual # admin URL. # from django.contrib import admin from django.contrib.admin import sites class FullAdminSite(admin.AdminSite): def has_permission(self, request): return request.user.is_superuser mysite = FullAdminSite("full-admin") admin.site = mysite sites.site = mysite
name = _("test menu") def get_nodes(self, request): nodes = [] n = NavigationNode(_('Blog'), "/{0}/blog/".format(request.LANGUAGE_CODE), 10) nodes.append(n) return nodes menu_pool.register_menu(TestMenu) class MyMode(Modifier): """ """ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): # print '-------' # print nodes for node in nodes: print node, node.url # blog = NavigationNode(_('Blog'), "/blog", 1) # blog.selected = False # nodes.insert(1, blog) return nodes menu_pool.register_modifier(MyMode)
"""Return menu's node for tags""" nodes = [] nodes.append( NavigationNode(_('Tags'), reverse('zinnia_tag_list'), 'tags')) for tag in tags_published(): nodes.append( NavigationNode(tag.name, reverse('zinnia_tag_detail', args=[tag.name]), tag.pk, 'tags')) return nodes class EntryModifier(Modifier): """Menu Modifier for entries, hide the MenuEntry 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'): node.visible = False return nodes menu_pool.register_menu(EntryMenu) menu_pool.register_menu(CategoryMenu) menu_pool.register_menu(AuthorMenu) menu_pool.register_menu(TagMenu) menu_pool.register_modifier(EntryModifier)
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_info == 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): """ Ask evildmp/superdmp if you don't understand softroots! Softroot description from the docs: A soft root is a page that acts as the root for a menu navigation tree. Typically, this will be a page that is the root of a significant new section on your site. When the soft root feature is enabled, the navigation menu for any page will start at the nearest soft root, rather than at the real root of
path = '{parent_url}{path_pattern}/'.format( parent_url=node.parent.get_absolute_url(), path_pattern=named_route_path_pattern) node_route['path'] = path node_route['name'] = slugify( path) # Use the same name for all nodes of this route. if named_route_path_pattern not in named_route_path_patterns.keys( ): # Store the index of this route in a dict of patterns. We need this to be able to override the # named route with the selected node (see the next condition). named_route_path_patterns[named_route_path_pattern] = len( router_nodes) elif node.selected: # Update the router config with the fetched data of the selected node. index_of_first_named_route = named_route_path_patterns[ named_route_path_pattern] node.attr['vue_js_route'] = node_route router_nodes[index_of_first_named_route] = node continue # Skip this iteration, we don't need to add a named route twice. else: continue # Ignore named routes for path patterns that have already been processed. node.attr['vue_js_route'] = node_route router_nodes.append(node) return router_nodes menu_pool.register_modifier(VueJsMenuModifier)
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)
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)
from menus.base import Modifier from menus.menu_pool import menu_pool from .constants import PLUGIN_URL_NAME_PREFIX from .models import AliasContent class AliasDisableMenu(Modifier): """Disable menu rendering on alias pages""" def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): if (request.toolbar.app_name == PLUGIN_URL_NAME_PREFIX or isinstance(request.toolbar.obj, AliasContent)): return [] return nodes menu_pool.register_modifier(AliasDisableMenu)
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)
from cms.models import Page from menus.base import Modifier from menus.menu_pool import menu_pool class PageExtendModifier(Modifier): """ """ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): if breadcrumb: return nodes for node in nodes: page = Page.objects.get(pk=node.id) pageextend = page.pageextend if hasattr(page, "pageextend") else None if pageextend: node.icon = pageextend.image node.touchable = pageextend.touchable node.authentication_required = pageextend.authentication_required return nodes menu_pool.register_modifier(PageExtendModifier)
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)
if entity.auto_contacts_page and "contacts" in menu_tests: menutitle = entity.contacts_page_menu_title new_node = NavigationNode(mark_safe(menutitle), entity.get_related_info_page_url('contact'), None) if new_node.get_absolute_url() in request.page_path: new_node.selected = True child.selected=False child.children.append(new_node) if getattr(entity, "auto_vacancies_page", None) and "vacancies" in menu_tests: menutitle = entity.vacancies_page_menu_title new_node = NavigationNode(mark_safe(menutitle), entity.get_related_info_page_url('vacancies-and-studentships'), None) if request.page_path == new_node.get_absolute_url(): new_node.selected = True child.selected=False child.children.append(new_node) if getattr(entity, "auto_publications_page", None) and entity.auto_publications_page and "publications" in menu_tests: menutitle = entity.publications_page_menu_title new_node = NavigationNode(mark_safe(menutitle), entity.get_related_info_page_url('publications'), None) if request.page_path == new_node.get_absolute_url(): new_node.selected = True child.selected=False child.children.append(new_node) except Page.DoesNotExist: pass self.recursive(request, child.children) menu_pool.register_modifier(ArkestraPages)
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)
# in case `menu_structure` is not present in config return nodes if post_cut: return nodes current_post = getattr(request, get_setting('CURRENT_POST_IDENTIFIER'), None) category = None if current_post and current_post.__class__ == Post: category = current_post.categories.first() if not category: return nodes for node in nodes: if '{0}-{1}'.format(category.__class__.__name__, category.pk) == node.id: node.selected = True return nodes menu_pool.register_modifier(BlogNavModifier) menu_pool.register_menu(BlogCategoryMenu) def clear_menu_cache(**kwargs): """ Empty menu cache when saving categories """ menu_pool.clear(all=True) post_save.connect(clear_menu_cache, sender=BlogCategory) post_delete.connect(clear_menu_cache, sender=BlogCategory)
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:
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)
""" 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)
for category in Category.objects.all().order_by("parent", "ordering"): nodes.append(NavigationNode(title=category.name, url=category.get_absolute_url(), id=category.pk, parent_id=category.parent_id, attr=dict(slug=category.slug))) return nodes class CategoryIcon(Modifier): """ navigation modifier that adds icon attribute """ icons = {} def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): if breadcrumb or not post_cut: return nodes ns = CatalogMenu.__name__ if not self.icons: for ci in CategoryImage.objects.filter(icon=True): self.icons[ci.category.pk] = ci.image.file.url if self.icons: for node in nodes: #print node.id, node.title, ', ns:', getattr(node, 'namespace', 'None') if node.namespace == ns and self.icons.get(node.id, None): node.attr['icon'] = self.icons.get(node.id) return nodes menu_pool.register_menu(CatalogMenu) menu_pool.register_modifier(CategoryIcon)
from menus.menu_pool import menu_pool class ZinniaMenuModifier(Modifier): """ """ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): """We want all parts of zinnia to show the blog selected.""" if post_cut: return nodes # Find out if it is a Zinnia Page try: blog_page = Page.objects.filter(title_set__application_urls="ZinniaApphook").get() except Page.DoesNotExist: blog_page = None if blog_page and request.path.startswith("/%s" % blog_page.get_path()): for node in nodes: if node.title == blog_page.get_title(): node.selected = True # Not sure what this does? count = 0 for node in nodes: node.counter = count count += 1 return nodes menu_pool.register_modifier(ZinniaMenuModifier)
nodes = [] nodes.append(NavigationNode(_('Tags'), reverse('zinnia_tag_list'), 'tags')) for tag in tags_published(): nodes.append(NavigationNode(tag.name, reverse('zinnia_tag_detail', args=[tag.name]), tag.pk, 'tags')) return nodes class EntryModifier(Modifier): """Menu Modifier for entries, hide the MenuEntry 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'): node.visible = False return nodes menu_pool.register_menu(EntryMenu) menu_pool.register_menu(CategoryMenu) menu_pool.register_menu(AuthorMenu) menu_pool.register_menu(TagMenu) menu_pool.register_modifier(EntryModifier)
from menus.base import Modifier from menus.menu_pool import menu_pool from menu_external_urls.models import MenuExternalUrl class MenuExternalUrlMod(Modifier): """ Adds ability to link page to an external URL. """ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): if post_cut: return nodes if breadcrumb: return nodes for node in nodes: try: #Load External URL into nodes menu_external_url = MenuExternalUrl.objects.get(page=(node.id-1)) node.url = menu_external_url.menu_external_url node.external = True except: pass return nodes menu_pool.register_modifier(MenuExternalUrlMod)
class Level(Modifier): """ marks all node levels """ post_cut = True def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): if breadcrumb: return nodes for node in nodes: if not node.parent: if post_cut: node.menu_level = 0 else: node.level = 0 self.mark_levels(node, post_cut) return nodes def mark_levels(self, node, post_cut): for child in node.children: # print child if post_cut: child.menu_level = node.menu_level + 1 else: child.level = node.level + 1 self.mark_levels(child, post_cut) menu_pool.register_modifier(Level)
def register(): menu_pool.register_modifier(Marker) menu_pool.register_modifier(LoginRequired) menu_pool.register_modifier(Level)
# -*- coding: utf-8 -*- """ admin.menu :copyright: (c) 2013 by Openlabs Technologies & Consulting (P) Limited :license: see LICENSE for more details. """ from menus.base import Modifier from menus.menu_pool import menu_pool from cms.models.pagemodel import Page class NodeModifier(Modifier): "NodeModifier" def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): """ Add attribute to point to page instance in NavigationMode """ for node in nodes: node.page = Page.objects.filter(pk=node.id)[0] return nodes menu_pool.register_modifier(NodeModifier)
"""Return menu's node for tags""" 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 NodetypeModifier(Modifier): """Menu Modifier for nodetypes, hide the MenuNodetype 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(NodetypeMenu) menu_pool.register_menu(MetatypeMenu) menu_pool.register_menu(AuthorMenu) menu_pool.register_menu(TagMenu) menu_pool.register_modifier(NodetypeModifier)