Sorry if the mail content is a bit lengthy, but I need to put all the info.<br><br>In the following code, there are 2 render functions:<br>- one using the interface (ok)<br>- the other uses the utility (ko)<br><br>Here is the code snippet:<br>
<br>-----<br>class AMenuItem(menu.BrowserMenuItem):<br> grok.implements(IAMenuItem, IMenuItemType)<br> grok.provides(IMenuItemType)<br> <a href="http://grok.name">grok.name</a>('menuitem')<br>
description = 'coucou'<br><br> def __init__(self, **kw):<br> <a href="http://self.kw">self.kw</a> = kw<br><br> def __call__(self, context, request):<br> super(menu.BrowserMenuItem, self).__init__(context, request)<br>
<br>grok.global_utility(AMenuItem)<br><br>class AMenuItemAdapter(grok.MultiAdapter):<br> grok.adapts(ICdcmenu, IBrowserRequest)<br> grok.implements(IAMenuItem)<br> title = 'hello'<br> description = 'toto'<br>
<br> def __init__(self, context, request):<br> self.context = context<br> self.request = request<br><br>class Index(grok.View):<br> grok.context(Cdcmenu)<br> a_menu = Menubar()<br>
a_menu('toto', 'Titre toto', 'Toto est de retour')<br> id = 'menuitem'<br><br> def getMenuItemType(self):<br> return component.getUtility(IMenuItemType, <a href="http://self.id">self.id</a>)<br>
<br># this function render correctly<br># def render(self):<br># resultat = []<br># for name, item in component.getAdapters((self.context, self.request), IAMenuItem):<br># resultat.append(item.description)<br>
# return pformat(resultat)<br><br># this function does not render correctly<br> def render(self):<br> resultat = []<br> for name, item in component.getAdapters((self.context, self.request), self.getMenuItemType()):<br>
resultat.append(item.description)<br> return pformat(resultat)<br>---<br><br>If I try to create a utility subclassing interface.Interface and implementing IMenuItemType like this:<br>
<br>class OtherMenuItem(interface.Interface):<br> grok.implements(IAMenuItem, IMenuItemType)<br><br>I get the following error:<br><br> File "/home/simon/.buildout/eggs/zope.interface-3.4.1-py2.4-linux-i686.egg/zope/interface/interface.py", line 488, in __init__<br>
raise InvalidInterface("Concrete attribute, " + name)<br>zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/mnt/backup_software/virtualgrok/Menutest/etc/site.zcml", line 4.2-4.32<br> ZopeXMLConfigurationError: File "/mnt/backup_software/virtualgrok/Menutest/src/menutest/configure.zcml", line 5.2-5.27<br>
InvalidInterface: Concrete attribute, __implements_advice_data__<br><br>Thanks for your help<br>Simon Elbaz<br><br><div class="gmail_quote">On Wed, Feb 4, 2009 at 2:37 AM, Dan Korostelev <span dir="ltr"><<a href="mailto:nadako@gmail.com">nadako@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2009/2/4 Simon Elbaz <<a href="mailto:elbazsimon9@gmail.com">elbazsimon9@gmail.com</a>>:<br>
<div class="Ih2E3d">> When I look to the getMenuItemType() function, it returns a utility (<br>
> return zope.component.getUtility(IMenuItemType, <a href="http://self.id" target="_blank">self.id</a>)) and the<br>
> consequence is that the adapter lookup returns nothing in getMenuItems.<br>
<br>
</div>That's strange, because that IMenuItemType utility is the interface<br>
that the menu item adapters are registered as providing. It works as<br>
intended here in plain zope3. Can you provide some more info?<br>
<font color="#888888"><br>
--<br>
WBR, Dan Korostelev<br>
</font></blockquote></div><br>