• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python menu_pool.get_nodes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中menus.menu_pool.menu_pool.get_nodes函数的典型用法代码示例。如果您正苦于以下问题:Python get_nodes函数的具体用法?Python get_nodes怎么用?Python get_nodes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_nodes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_menu_nodes

    def test_menu_nodes(self):
        """
        Tests if all categories are present in the menu
        """
        posts = self.get_posts()
        pages = self.get_pages()
        self.reload_urlconf()

        for lang in ('en', 'it'):
            with smart_override(lang):
                request = self.get_page_request(pages[1], self.user, pages[1].get_absolute_url(lang))
                nodes = menu_pool.get_nodes(request)
                nodes_url = set([node.url for node in nodes])
                cats_url = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(lang)])
                self.assertTrue(cats_url.issubset(nodes_url))

        cache.clear()
        posts[0].categories.clear()
        for lang in ('en', 'it'):
            with smart_override(lang):
                request = self.get_page_request(pages[1], self.user, pages[1].get_absolute_url(lang))
                nodes = menu_pool.get_nodes(request)
                nodes_url = set([node.url for node in nodes])
                self.assertFalse(posts[0].get_absolute_url(lang) in nodes_url)
                self.assertTrue(posts[1].get_absolute_url(lang) in nodes_url)
开发者ID:Darex1991,项目名称:djangocms-blog,代码行数:25,代码来源:test_menu.py


示例2: test_menu_nodes

 def test_menu_nodes(self):
     """
     Tests if all categories are present in the menu
     """
     for lang in ('en', 'it'):
         request = self.get_page_request(None, self.user,
                                         r'/%s/blog/' % lang, edit=False)
         activate(lang)
         nodes = menu_pool.get_nodes(request, namespace='BlogCategoryMenu')
         nodes_copy = copy.deepcopy(nodes)
         for cat in self.cats:
             if not cat.has_translation(lang):
                 continue
             with switch_language(cat, lang):
                 # find in node list
                 found = None
                 for node in nodes_copy:
                     if node.url == cat.get_absolute_url():
                         found = node
                         break
                 self.assertIsNotNone(found)
                 nodes_copy.remove(found)
                 self.assertEqual(node.id, cat.id)
                 self.assertEqual(node.title, cat.name)
         # check that all categories were found in menu
         self.assertEqual(len(nodes_copy), 0)
开发者ID:rmoorman,项目名称:djangocms-blog,代码行数:26,代码来源:test_menu.py


示例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        
开发者ID:Natim,项目名称:django-cms-2.0,代码行数:29,代码来源:menu_tags.py


示例4: get_context

    def get_context(self, context, template, name ):
        try:
            request = context['request']
        except KeyError:
            return { 'template': 'menu/empty.html' }
        
        all_nodes = menu_pool.get_nodes(request)
        nodes = menu_pool.get_nodes_by_attribute(all_nodes, 'type', 'family')

        for node in nodes:
            if (node.ancestor or node.selected) and node.attr['type'] == 'family':
                break
            if node.descendant: # We must be at a designer
                node.selected = True # This must be the first family, so select it
                break

        if node.selected: # We're at a family or designer, so automatically select the first stamp
          node.children[0].selected = True

        try:
            context = { 'children': node.children }
        except:
            context = { 'template': template}
            
        return context
开发者ID:samjacoby,项目名称:katran,代码行数:25,代码来源:stamps_tags.py


示例5: test_modifier

 def test_modifier(self):
     """
     Tests if correct category is selected in the menu
     according to context (view object)
     """
     post1, post2 = self.get_posts()
     tests = (
         # view class, view kwarg, view object, category
         (PostDetailView, 'slug', post1, post1.categories.first()),
         (CategoryEntriesView, 'category', self.cats[2], self.cats[2])
     )
     for view_cls, kwarg, obj, cat in tests:
         request = self.get_page_request(None, self.user, r'/en/blog/', edit=False)
         activate('en')
         with switch_language(obj, 'en'):
             view_obj = view_cls()
             view_obj.request = request
             view_obj.kwargs = {kwarg: obj.slug}
             view_obj.get(request)
             # check if selected menu node points to cat
             nodes = menu_pool.get_nodes(request, namespace='BlogCategoryMenu')
             found = False
             for node in nodes:
                 if node.selected:
                     self.assertEqual(node.url, cat.get_absolute_url())
                     found = True
                     break
             self.assertTrue(found)
开发者ID:rmoorman,项目名称:djangocms-blog,代码行数:28,代码来源:test_menu.py


示例6: render

		def render(self, context, instance, placeholder):

				try:
						# If there's an exception (500), default context_processors may not be called.
						request = context['request']
				except KeyError:
						return "There is no	`request` object in the context."

				root_page = instance.root
				root_page_url = root_page.get_absolute_url()
				from_level = instance.start_level
				to_level = instance.depth

				nodes = menu_pool.get_nodes(request)

				children = list()
				root_node = None

				# Find the root node
				for node in nodes:
						if not root_node and node.url == root_page_url:
								root_node = node

				if root_node:
						if instance.include_root :
								children += (root_node, )
						else:
								children += root_node.children

				context.update({
						'MenuItems' : children,
				})
				return context
开发者ID:nephila,项目名称:cmsplugin-embedded-menu,代码行数:33,代码来源:cms_plugins.py


示例7: get_context

    def get_context(self, context, **kwargs):

        menu_name = kwargs.pop('menu_name')

        context.update({'children': [],
                        'template': kwargs.get('template'),
                        'from_level': kwargs.get('from_level'),
                        'to_level': kwargs.get('to_level'),
                        'extra_inactive': kwargs.get('extra_inactive'),
                        'extra_active': kwargs.get('extra_active'),
                        'namespace': kwargs.get('namespace')
                        })

        try:
            named_menu = CMSNamedMenu.objects.get(name__iexact=menu_name).pages
        except ObjectDoesNotExist:
            logging.warn("Named CMS Menu %s not found" % menu_name)
            return context

        nodes = menu_pool.get_nodes(context['request'], kwargs['namespace'], kwargs['root_id'])

        context.update({
            'children': self.arrange_nodes(nodes, named_menu, namespace=kwargs['namespace'])
        })

        return context
开发者ID:jakob-o,项目名称:django-cms-named-menus,代码行数:26,代码来源:named_cms_menu_tags.py


示例8: test_modifier

    def test_modifier(self):
        """
        Tests if correct category is selected in the menu
        according to context (view object)
        """
        posts = self.get_posts()
        pages = self.get_pages()

        tests = (
            # view class, view kwarg, view object, category
            (PostDetailView, "slug", posts[0], posts[0].categories.first()),
            (CategoryEntriesView, "category", self.cats[2], self.cats[2]),
        )
        for view_cls, kwarg, obj, cat in tests:
            request = self.get_page_request(pages[1], self.user, path=obj.get_absolute_url())
            with smart_override("en"):
                with switch_language(obj, "en"):
                    view_obj = view_cls()
                    view_obj.request = request
                    view_obj.namespace, view_obj.config = get_app_instance(request)
                    view_obj.app_config = self.app_config_1
                    view_obj.kwargs = {kwarg: obj.slug}
                    view_obj.get(request)
                    # check if selected menu node points to cat
                    nodes = menu_pool.get_nodes(request, namespace="BlogCategoryMenu")
                    found = False
                    for node in nodes:
                        if node.selected:
                            self.assertEqual(node.url, obj.get_absolute_url())
                            found = True
                            break
                    self.assertTrue(found)
开发者ID:danra,项目名称:djangocms-blog,代码行数:32,代码来源:test_menu.py


示例9: test_public_menu_anonymous_user

 def test_public_menu_anonymous_user(self):
     """
     Anonymous user should only see the pages in the rendered menu
     that have no permissions assigned,directly or indirectly
     """
     self._setup_user_groups()
     all_pages = self._setup_tree_pages()
     self._setup_view_restrictions()
     granted = ['page_a',
         'page_c',
         'page_c_a',
         'page_c_b',
         'page_d_a',
         'page_d_b',
         'page_d_c',
         'page_d_d'
     ]
     self.assertGrantedVisibility(all_pages, granted)
     urls = self.get_url_dict(all_pages)
     user = AnonymousUser()
     request = self.get_request(user, urls['/en/'])
     nodes = menu_pool.get_nodes(request)
     self.assertEqual(len(nodes), 4)
     self.assertInMenu(urls["/en/"], user)
     self.assertInMenu(urls["/en/page_c/"], user)
     self.assertInMenu(urls["/en/page_c/page_c_a/"], user)
     self.assertInMenu(urls["/en/page_c/page_c_b/"], user)
     self.assertViewNotAllowed(urls["/en/page_b/"], user)
     self.assertNotInMenu(urls["/en/page_b/"], user)
     self.assertViewNotAllowed(urls["/en/page_d/"], user)
     self.assertNotInMenu(urls["/en/page_d/"], user)
开发者ID:AllenYang0308,项目名称:django-cms,代码行数:31,代码来源:menu_page_viewperm.py


示例10: kipp_sub_menu

def kipp_sub_menu(context, template="menu/sub_menu.html"):
    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)
    parent_node = None
    children = []    
    for node in nodes:
        if (node.level == 1) or (node.get_attribute("reverse_id")=="get-involved"): 
            if (node.ancestor) or (node.selected):
                parent_node = node
            if parent_node is None:
                pass
            else:
                children = parent_node.children
    context.update({'children':children,
                    'template':template,
                    'from_level':0,
                    'to_level':0,
                    'extra_inactive':0,
                    'extra_active':0
                    })
    return context 
开发者ID:barbarae,项目名称:kipp,代码行数:25,代码来源:kipp.py


示例11: 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
开发者ID:kewinwang,项目名称:django-cms,代码行数:26,代码来源:menu_tags.py


示例12: get_queryset

 def get_queryset(self):
     site = get_current_site(self.request)
     if self.action == 'menu':
         return menu_pool.get_nodes(self.request, site_id=site.pk)
     if use_draft(self.request):
         return Page.objects.drafts().on_site(site=site).distinct()
     else:
         return Page.objects.public().on_site(site=site).distinct()
开发者ID:nephila,项目名称:djangocms-rest-view,代码行数:8,代码来源:views.py


示例13: _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
开发者ID:team-xue,项目名称:xue,代码行数:58,代码来源:menu_tags.py


示例14: 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
开发者ID:Ratnam123,项目名称:WFIMS,代码行数:57,代码来源:fix_menu_tags.py


示例15: assertNotInMenu

 def assertNotInMenu(self, page, user):
     request = self.get_request(user, page)
     nodes = menu_pool.get_nodes(request)
     target_url = page.get_absolute_url()
     found_in_menu = False
     for node in nodes:
         if node.get_absolute_url() == target_url:
             found_in_menu = True
             break
     self.assertFalse(found_in_menu)
开发者ID:AllenYang0308,项目名称:django-cms,代码行数:10,代码来源:menu_page_viewperm.py


示例16: test_public_pages_anonymous_norestrictions

 def test_public_pages_anonymous_norestrictions(self):
     """
     All pages are visible to an anonymous user
     """
     all_pages = self._setup_tree_pages()
     request = self.get_request()
     visible_page_ids = get_visible_pages(request, all_pages, self.site)
     self.assertEqual(len(all_pages), len(visible_page_ids))
     nodes = menu_pool.get_nodes(request)
     self.assertEqual(len(nodes), len(all_pages))
开发者ID:AllenYang0308,项目名称:django-cms,代码行数:10,代码来源:menu_page_viewperm.py


示例17: serialize_navigation

    def serialize_navigation(self, request):

        nodes = menu_pool.get_nodes(request)

        cleaned = []

        for node in nodes:
            node.children = None
            node.parent = None
            cleaned.append(node.__dict__)

        return json.dumps(cleaned, cls=LazyEncoder)
开发者ID:jakob-o,项目名称:django-cms-named-menus,代码行数:12,代码来源:admin.py


示例18: test_get_menus

    def test_get_menus(self):
        """
        Check that menus are dynamically loaded according to the different page the apphook is
        attached to
        """
        titles = self.create_base_structure('VariableUrlsApp', ['en', 'de'])
        titles[0].page.reverse_id = 'page1'
        titles[0].page.save()
        cache.clear()
        self.reload_urls()
        menu_pool.discover_menus()
        cache.clear()

        request = self.get_request('/')
        nodes = menu_pool.get_nodes(request)
        nodes_urls = [node.url for node in nodes]
        self.assertTrue(reverse('sample-account') in nodes_urls)
        self.assertFalse('/en/child_page/page2/' in nodes_urls)

        self.reload_urls()
        self.apphook_clear()

        cache.clear()
        self.reload_urls()

        page2 = create_page('page2', 'nav_playground.html',
                            'en', created_by=self.superuser, published=True,
                            parent=titles[0].page.get_draft_object().parent,
                            in_navigation=True,
                            apphook='VariableUrlsApp', reverse_id='page2')
        create_title('de', 'de_title', page2, slug='slug')
        page2.publish('de')
        request = self.get_request('/page2/')
        nodes = menu_pool.get_nodes(request)
        nodes_urls = [node.url for node in nodes]
        self.assertTrue(reverse('sample-account') in nodes_urls)
        self.assertTrue(reverse('sample2-root') in nodes_urls)
        self.assertTrue('/static/fresh/' in nodes_urls)

        self.apphook_clear()
开发者ID:intexal,项目名称:my-first-blog,代码行数:40,代码来源:test_apphooks.py


示例19: _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
开发者ID:laurafeier,项目名称:django-cms-blogger,代码行数:13,代码来源:admin.py


示例20: test_menu_nodes

    def test_menu_nodes(self):
        """
        Tests if all categories are present in the menu
        """
        self.get_posts()
        self.get_pages()

        for lang in ("en", "it"):
            request = self.get_page_request(None, self.user, r"/%s/page-two/" % lang)
            with smart_override(lang):
                nodes = menu_pool.get_nodes(request, namespace="BlogCategoryMenu")
                nodes_url = set([node.url for node in nodes])
                cats_url = set([cat.get_absolute_url() for cat in self.cats if cat.has_translation(lang)])
                self.assertTrue(cats_url.issubset(nodes_url))
开发者ID:danra,项目名称:djangocms-blog,代码行数:14,代码来源:test_menu.py



注:本文中的menus.menu_pool.menu_pool.get_nodes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python menu_pool.register_menu函数代码示例发布时间:2022-05-27
下一篇:
Python menu_pool.discover_menus函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap