Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Newly created instances of NavigationNode doesn't have important attributes #907

Closed
neoascetic opened this Issue · 5 comments

4 participants

@ojii
Collaborator

From that thread:

Hi all.
After an app integration I'm try to extend menu (with specified ID) with links to views of my app. I'm use for this Navigation Modifiers.
Here code of meny.py:

from menus.base import Modifier, NavigationNode
from menus.menu_pool import menu_pool

class MyNode(Modifier):
        name = 'mymenu'
        def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
                if post_cut: return nodes
                if root_id == 'top_menu':
                        nodes.append(NavigationNode('test', '/', 1))
                return nodes

menu_pool.register_modifier(MyNode)

cms_app.py:

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from standard_projects.menu import MyNode

from django.utils.translation import ugettext_lazy as _

class StandardProjectsApp(CMSApp):
        name = _('Standard projects')
        urls = ['standard_projects.urls']
        menu = [MyNode]

apphook_pool.register(StandardProjectsApp)

And when I try access a page with this menu, django crash with Error:
Caught AttributeError while rendering: 'NavigationNode' object has no attribute 'selected'

When I try to print dir(nodes[0]) in modify function of MyMenu, it's show NavigationNodes with this attribute, but when I try do this with my newly created node, it doesn't have this attribute.
What I'm doing wrong? Maybe here another ways to extend menu with specified ID?

@ojii
Collaborator

Now you're doing a thing here that was never intended to be done, adding navigation nodes in modifiers. Modifiers should just alter existing navigation nodes, while navigation nodes should be attached using Menu/CMSAttachMenu subclasses.

Therefore I'll close this as a WONTFIX for now

@ojii ojii closed this
@kezabelle

Note that while it may not have been intended to be done, the documentation has always been rather ambiguous - it talked of adding and changing properties, but those without a keen understanding of the underlying intention may not have understood that correctly.

However, in the develop docs it now explicitly says that adding navigation nodes via a modifier is OK. I wonder: Is that intentional (and a change in stance) or an error in the updated docs?

@ojii ojii reopened this
@ojii
Collaborator

This might indeed be a documentation issue

@ojii ojii closed this issue from a commit
@ojii ojii Fixed #907 f7757f4
@ojii ojii closed this in f7757f4
@chhantyal

I too fell into this documentation trap on latest.

While this f7757f4 says it can change existing, the docs implies Modifier can be used to add new nodes as well or at least it's not explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.