[Zope-CMF] Re: How do deal with cmfcatalog-wrapped objects?
Andreas Jung
lists at andreas-jung.com
Fri Apr 7 01:38:46 EDT 2006
Both solution appear a bit "heavy" to me. I solved this issue for
TextIndexNG3 by adding generic support for wrapped objects by introducing an
IObjectWrapper interface which is checked by the indexer. Using
five:implements it is easy to attach this interface - if necessary - to any
wrapper class (including IndexableObjectWrapper at CMFCore). Writing an adapter
for adapting IndexableObjectWrapper to IObjectWrapper is trivial. I think
this solution is more straight forward and does not require any changes
to the CMF.
-aj
--On 31. März 2006 14:11:58 +0200 Philipp von Weitershausen
<philipp at weitershausen.de> wrote:
>
> 1. I think for the long term, IndexableObjectWrapper could be made a
> decorator. This works as follows:
>
> from zope.proxy import getProxiedObject
> from zope.app.decorator import Decorator
>
> class IndexableObjectWrapper(Decorator):
>
> def allowedRolesAndUsers(self):
> ob = getProxiedObject(self)
> allowed = {}
> for r in rolesForPermissionOn(View, ob):
> allowed[r] = 1
> localroles = _mergedLocalRoles(ob)
> for user, roles in localroles.items():
> for role in roles:
> if allowed.has_key(role):
> allowed['user:' + user] = 1
> if allowed.has_key('Owner'):
> del allowed['Owner']
> return list(allowed.keys())
>
> 2. In the short term we can apply the following trick
> (IndexableObjectWrapper needs to be a new style class!):
>
> from zope.interface import providedBy
> from zope.interface.declarations import ObjectSpecificationDescriptor
> from zope.interface.declarations import getObjectSpecification
> from zope.interface.declarations import ObjectSpecification
>
> class IndexableObjectSpecification(ObjectSpecificationDescriptor):
>
> def __get__(self, inst, cls=None):
> if inst is None:
> return getObjectSpecification(cls)
> else:
> provided = providedBy(inst.__ob)
> cls = type(inst)
> return ObjectSpecification(provided, cls)
>
> class IndexableObjectWrapper(object): # new-style!
> implements(...) # it can implement as much as it wants
> __providedBy__ = IndexableObjectSpecification()
>
> ...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-cmf/attachments/20060407/4ab90197/attachment.bin
More information about the Zope-CMF
mailing list