Il 05/07/2010 15:18, Andreas Jung ha scritto:
>>>> value = ad.some_method(some_args)
>>>>
>>>>
>>>>
>> this gives me AttributeError: some_method
>>
>>
> The adapter of course has to implement some_method().
>
Thanks!
I've found the solution :)
Legend:
IDocumentExtended -> p4a.subtyper, I switch a Document from normal to
extended
IMethodAdd -> an interface to tell "this implement a new method" (
here a hello method)
=========== interfaces.py =========
from zope.interface import Interface
from zope.app.content import interfaces as contentifaces
from zope import interface
class IDocumentExtended(Interface):
""" Marker interface to extend a Document """
pass
class IMethodAdd(Interface):
""" a method add interface """
def hello():
pass
#class IAddMethod(Interface):
# """ a method add interface """
# def ciao():
# pass
interface.alsoProvides(IDocumentExtended, contentifaces.IContentType)
====================== metaadapter.py ===============
from zope.component import adapts
from zope.interface import implements
from interfaces.interfaces import IDocumentExtended
from interfaces.interfaces import IMethodAdd
class MethodAdapter(object) :
implements(IMethodAdd)
adapts(IDocumentExtended)
def __init__(self, context):
self.context = context
def hello(self):
return "hello!"
====================== configure.zcml =======
<adapter
for=".interfaces.interfaces.IDocumentExtended"
provides=".interfaces.interfaces.IMethodAdd"
factory=".metaadapter.MethodAdapter"
/>
this:
<adapter factory=".metaadapter.MethodAdapter" />
works too.
=======================
I call it with:
a = IMethodAdd(self.my_object)
return a.hello()
now, I would like to avoid the a = IMethodAdd(self.my_object) and call
directly self.my_object.hello()
Any idea?
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers