[Grok-dev] Dependency between classes to be grokked
Santiago Videla
santiago.videla at gmail.com
Sat Dec 13 00:53:14 EST 2008
Hi,
I'm working on megrok.menu
As far I understand, it hasn't the possibility to use sub-menus, and I would
like to use those.
I was trying to understand how Menu, MenuItems and SubMenuItems are
registered and what I "understood" is that sub-menus must be registered
first, as a MenuBrowser (using menuDirective) and then as a
SubMenuItemBrowser (using subMenuItemDirective)
So what I did was to add the megrok.menu.menuitem directive to the
MenuGrokker (until now, was only available for MenuItemGrokker) and the
execute method for the MenuGrokker is the following
def execute(self, factory, config, name, title, description, \
menuitem=None, context=None, layer=None,
permission=None):
menuDirective(config, id=name, class_=factory,
title=title, description=description)
# If menuitem directive is used, then we have to register the
#grokked Menu as a MenuItem for another Menu
if menuitem:
menu_id, icon, filter, order = menuitem
try:
menu = config.resolve('zope.app.menus.'+menu_id)
except ConfigurationError, v:
raise GrokError("The %r menu could not be found. Please use
"
"megrok.menu.Menu to register a menu first."
% menu_id, factory)
subMenuItemDirective(config, menu=menu, for_=context,
submenu=name,
title=title, description=description,
icon=icon,
filter=filter, permission=permission,
layer=layer,
order=order, action='')
return True
The problem that I found is that
menu = config.resolve('zope.app.menus.'+menu_id)
It's not always resolved. It depends on the class names. The relation that I
found was that Menu classes are grokked in alphabetic order, am I right?
Example:
class Clients(megrok.menu.Menu):
grok.name('clients_menu')
grok.title('Clients')
megrok.menu.menuitem('main_menu')
def render(self):
pass
class ClientsItem(grok.View):
grok.title('Addclient')
megrok.menu.menuitem('clients_menu')
def render(self):
return 'add client view'
class MainMenu(megrok.menu.Menu):
grok.name('main_menu')
grok.title('Main menu')
grok.description('App menu')
this doesn't work, because Clients(megork.menu.Menu) is grokked before
MainMenu
if I change Clients to NClients (N after M) it does work, but I guess that
it's not the solution to this problem...
I already try to make 2 different grokkers with differents priorities (using
martian.priority) but nothing changes
I need some help... please :)
Regards
--
Santiago Videla
www.revolucionesweb.com.ar
http://www.linkedin.com/in/svidela
Sigue la mata dando de que hablar siempre abajo y a la izquierda donde el
pensamiento que se hace corazón resplandece con la palabra sencilla y
humilde que l at s tod at s somos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20081213/039b4144/attachment.html
More information about the Grok-dev
mailing list