[Plone-IT] utilizzare getToolByName()

Nicola Senno biancosteso a yahoo.it
Lun 8 Ott 2007 10:37:29 UTC


ho seguito il tuo consiglio e ho trovato queste informazioni:
da parts/zope2/lib/python/zope/component/bbb/interfaces.py

class IContextDependent(Interface):
    """Components implementing this interface must have a context component.

    Usually the context must be one of the arguments of the
    constructor. Adapters and views are a primary example of
context-dependent
    components.
    """

    context = Attribute(
        """The context of the object

        This is the object being adapted, viewed, extended, etc.
        """)

allora ho modificato la mia interfaccia IDynamicMenu in questo modo:

.....
from zope.component.bbb.interfaces import IContextDependent

class IDynamicMenu(IContextDependent):
    """
    """
    
    def getMenu():
        """ ritorna un menu in xhtml"""

procedo con la costruzione della classe:

...
class NavigationMenu(object):

    implements(IDynamicMenu)

    def __init__(self, context):
    	self.context = context
    ...

ma l'errore rimane:

2007-10-08 11:18:14 INFO Zope Ready to handle requests
<Assignment at >  
<---------------------------------------------------------- qui ho fatto un
print self.context nella classe NavigationMenu
2007-10-08 11:18:37 ERROR Zope.SiteErrorLog
http://localhost:8080/portal/getReply/getReply
Traceback (innermost last):
  Module ZPublisher.Publish, line 119, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 42, in call_object
  Module Products.kssdnd.browser.dragSupport, line 57, in getReply
  Module Products.kssdnd.browser.navigationMenu, line 73, in getMenu
  Module Products.kssdnd.browser.navigationMenu, line 60, in getObject
  Module Products.kssdnd.browser.navigationMenu, line 47, in getObjectRef
  Module Products.CMFCore.utils, line 123, in getToolByName
AttributeError: portal_catalog


dove ho sbagliato?


Riccardo Lemmi wrote:
> 
> On Sunday 07 October 2007 17:40, Nicola Senno wrote:
>> Grazie Riccardo
>>
>> ho già provato ad usare "self.context" ma non risolve il mio problema.
>> Credo che l'errore sia dovuto al fatto che il context è vuoto (ho provato
>> a
>> stampare self.context ed è vuoto), in ogni caso ho postato
>> http://www.nabble.com/portlet-reference-from-hash-code-tf4269138s6741.html
>> qui  tutte le informazioni a riguardo con maggiori dettagli sul codice
>> eseguito.
>>
>> Nicola
> 
> self.context vuoto mi hai fatto venire in mente una cosa che avevo notato
> nel 
> tuo codice e che non mi tornava, il tuo adapter non è un adapter. Infatti
> il 
> metodo __init__ dovrebbe prende almeno un parametro:
> 
>     def __init__(self, context):
>         self.context = context
> 
> se invece usi una classe base tipo BrowserView (che è un multi-adapter) il 
> costruttore prende due parametri: context e request, vedi ad esempio:
> class BrowserView(Location):
>     ...
>     implements(IBrowserView)
> 
>     def __init__(self, context, request):
>         self.context = context
>         self.request = request
> 
> -- 
> Riccardo Lemmi                           Email:   riccardo a reflab.it
> Reflab S.r.l. - Plone Design, Development and Consulting
> Phone: +39 349 4620820                         http://www.reflab.it
> 
>  
> _______________________________________________
> Plone-IT mailing list
> Plone-IT a lists.plone.org
> http://lists.plone.org/mailman/listinfo/plone-it
> http://www.nabble.com/Plone---Italy-f21728.html
> 

-- 
View this message in context: http://www.nabble.com/utilizzare-getToolByName%28%29-tf4574392s21526.html#a13094072
Sent from the Plone - Italy mailing list archive at Nabble.com.





Maggiori informazioni sulla lista Plone-IT