[CPS-devel] Proxies and interfaces

Florent Guillaume fg at nuxeo.com
Fri Jun 30 15:14:13 CEST 2006


It's probably not wise to copy all the provided interfaces from the  
object, you should only copy those dealing with views or that you  
know you're interested in.


On 30 Jun 2006, at 14:04, Santi Camps wrote:

> On 6/29/06, Florent Guillaume <fg at nuxeo.com> wrote:
>> Unfortunately the proxies rely on acquisition to get proper skins, so
>> zope 3 views can't be used directly.
>
> It's working for me, using Five.  I'm using Zope 2.9.x, so acquisition
> is still implicit.
>
>> On the other hand, you can create a specific view for ICPSProxy that
>> knows that it deals with a proxy and not a doc so can do getContent()
>> at the appropriate place. But this view will be for all proxies, not
>> just those of your docs.
>>
>> This whole system was designed before anything like zope 3 views
>> existed, it's not easy to retrofit it now.
>>
>> It's probably possible to make a proxy provide a specific interface
>> after it's been created, the have your view use that. You could try
>> prototyping it by adding the interface on one proxy from the ZMI
>> (Interface tab, you'll have to define a marker interface for your use
>> and bind the view to it) and check the view works.
>>
>> Florent
>
> Sure, it works fine !!   And it seems very useful to me, so I can
> register views using ZCML and apply them to the proxies, but only to
> those proxies proxying an object that implements the wanted interface.
>
> If you are interested, with this little code all this is done  
> automatically:
>
>
> from Products.CPSCore.interfaces import ICPSProxy
> from Products.Five.utilities.interfaces import IReadInterface,  
> IWriteInterface
>
> def addProxiedInterfaces(proxy, event):
>    """
>    Register all interfaces provided by proxied object as proxy own  
> interfaces
>    If proxied is None, is due to the proxy is created before the
> proxied object
>    itself
>    """
>    proxied = proxy.getContent()
>    if proxied:
>        proxy_adapter = IWriteInterface(proxy)
>        proxied_adapter = IReadInterface(proxied)
>        proxy_adapter.update(add=tuple(proxied_adapter.getProvided()))
>
>
> def addInterfacesToAllProxies(proxied, event):
>    """
>    Register all interfaces provided by proxied to all its proxies
>    """
>    docid = proxied.getId().split('_')[0]
>    all_proxies = proxied.portal_proxies.listProxies(docid=docid)
>    proxied_adapter = IReadInterface(proxied)
>    interfaces = tuple(proxied_adapter.getProvided())
>    for x in all_proxies:
>        proxy = proxied.unrestrictedTraverse(x[0])
>        proxy_adapter = IWriteInterface(proxy)
>        proxy_adapter.update(add=interfaces)
>
>
> And in configure.zcml:
>
>    <subscriber
>        for="Products.CPSCore.interfaces.ICPSProxy
>             zope.app.container.interfaces.IObjectAddedEvent"
>        factory=".proxy.addProxiedInterfaces"
>        />
>
>    <subscriber
>        for="Products.CPSDocument.interfaces.ICPSDocument
>             zope.app.container.interfaces.IObjectAddedEvent"
>        factory=".proxy.addInterfacesToAllProxies"
>        />
>
>
> Thanks a lot for your help
> -- 
> Santi Camps
> Earcon S.L. - http://www.earcon.com
>                  - http://www.kmkey.com

-- 
Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com





More information about the cps-devel mailing list

This list archive provided by Nuxeo, the leaders of open source ECM. Check out the Nuxeo 5 open source, standards-based ECM project.