[Zope-CMF] Re: small proposal, catalog tool

2005-08-29 Thread whit

or even::

 

and then have the catalog look for all such adapters when indexing content.



that seems to make the most sense and requires no extra lingo in the zcml.

-w

___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


[Zope-CMF] Re: small proposal, catalog tool

2005-08-29 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

whit wrote:
> doh...
> 
>> > for=".interfaces.IMyContent"
>> provides=".interfaces.ISomeCalledInterface"
>> factory=".SomeCallabelAdapter"
>> permission="zope2.Public"
>> />
>>
> 
> could be simpler (no need for factory or permission), just:
> 
>  for=".interfaces.IMyContent"
> index=".interfaces.ISomeCalledInterface"
> />

or even::

 

and then have the catalog look for all such adapters when indexing content.

Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDExoS+gerLs4ltQ4RArfqAKCodEU6wnCskxYT5aO8uZAxN3zgSQCeM8US
DnMy/B6KL4NqTb9pJnuuGO0=
=aNwX
-END PGP SIGNATURE-

___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


[Zope-CMF] Re: small proposal, catalog tool

2005-08-29 Thread whit

doh...






could be simpler (no need for factory or permission), just:




-w

___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


[Zope-CMF] Re: small proposal, catalog tool

2005-08-28 Thread whit
tackling this problem a little bit ago, I found it helpful to create 
adapters that returned values to index rather than gronky objects (see 
the first attachment. undoubtably there could be discussion about 
whether this is useful or just lazy, but I think it could promote code 
reuse and less pointlessly named "adapter" vars cluttering the namespace).


This let me use a simple closure and loop to register adapters for 
indexing using plones ExtensibleObjectWrapper:


from Products.CMFPlone.CatalogTool import registerIndexableAttribute

def registerIndexer(idx, iface):
default = None

def indexfx(obj, portal, **kw):
try:
return iface(obj)
except TypeError:
return default

registerIndexableAttribute(idx, indexfx)

iface_idxs = (('index1', ISomeCalledInterface),
  ('index2', ISomeOtherCalledInterface))

for name, iface in iface_idxs:
registerIndexer(name, iface)


Getting back to pete's points, I think another tool would be overkill, 
but something like registerIndexer might work as a directive that could 
be associated to content ala:





-w


##
#
# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##
"""
An interface that returns a value if adapter or directly provided object is 
callable
"""
from zope.interface.interface import InterfaceClass, adapter_hooks
from zope.interface.interfaces import IInterface
from zope.interface.declarations import classImplements

class CalledInterfaceClass(InterfaceClass):

def _callOrReturn(self, obj):
if callable(obj):
return obj()
else:
return obj

def __adapt__(self, obj):
if self.providedBy(obj):
return self._callOrReturn(obj)

for hook in adapter_hooks:
adapter = hook(self, obj)
if adapter is not None:
return self._callOrReturn(adapter)

classImplements(InterfaceClass, IInterface)

CalledInterface = CalledInterfaceClass("CalledInterface", __module__ = 
'Products.calledinterface')

__all__=('CalledInterface')
___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


[Zope-CMF] Re: small proposal, catalog tool

2005-08-20 Thread computing project
I had a look at the plone way of doing it - it is basically the same 
requirement, AFAICS (always good to know :-) ).


I definitely prefer the 'concreteness' of having an interface: for me, the 
drawback about the plone way of doing it, for me, that the code about how to 
calculate the attribute lived outside of the tool class, but the tool was 
responsible for providing it.  For example, 'syndication_enabled' should be 
a variable provided directly by the syndication tool rather than somewhere 
else.


I think the approach I outlined could work for plone with only a minor 
change: recasting the extensible-indexable-object-wrapper into a 
'catalog_registry' tool that provided the necessary interface, and supported 
registerIndexableAttribute.  The functions in CMFPlone.CatalogTool could 
then register with that transparently.  I think it would be straightforward 
to do this, and it would help me to test things out, so I can do that and 
submit it to you/plone/mailing list if it's useful.


Incidentally, CPS patches CatalogTool with its own version of 
indexableobjectwrapper which provides some more general catalog information 
about paths and depths, etc, and my approach would remove the need for this 
to be done in a patch.


pete

_
Be the first to hear what's new at MSN - sign up to our free newsletters! 
http://www.msn.co.uk/newsletters


___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


[Zope-CMF] Re: small proposal, catalog tool

2005-08-19 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Alec Mitchell wrote:
> On Friday 19 August 2005 04:03 pm, computing project wrote:
> 
>>Hi,
>>
>>I'd like to change the way that the catalog is implemented slightly, to
>>allow tools other than the workflow tool to provide variables to the
>>catalog.  I'm happy to submit the code + tests if everyone's
>>happy/interested.
>>
>>1.  Provide a new interface.  Currently, only the workflow tool implements
>>this interface
>>
>>class ICatalogVariableProvider(Interface):
>>
>>  def getCatalogVariablesFor(obj):
>> """Return a dictionary of additional properties to be made available
>>to the catalog when an object is indexed
>> """
>> return vars
>>
>>2.  Change the catalog tool to something like:
>>
>>  def catalog_object(self, obj, uid, idxs=None, update_metadata=1):
>>vars = {}
>>for tool in self._providers:
>>   pt = getToolByName(obj, tool, None)
>>   if pt:
>>  vars.update( pt.getCatalogVariablesFor( obj ) )
>>
>>w = IndexableObjectWrapper(vars, obj)
>>ZCatalog.catalog_object(self, w, uid, idxs, update_metadata)
>>
>>  where at the moment, _providers would be just a one-item tuple (
>>'portal_workflow', )
>>
>>This way it's much easier to hook other tools in at indexing time by adding
>>them to the list, rather than needing to create a new catalog class.  (note
>>this code is a rough cut-and-paste, so it might well have typos - for
>>illustration only!)
>>
>>Any thoughts?  Is this useful?
> 
> 
> In Plone 2.1 we have an ExtensibleIndexableObjectWrapper which allows 
> products 
> to register methods with the catalog for use in indexing and metadata.  I 
> think this handles the same (or similar) usecases in a different but 
> potentially more flexible manner.  Plone uses it to register all sorts of 
> tool methods, rather than indexing python scripts or something similarly 
> inefficient.  Hopefully this might make it into the CMF core at some point.

In a Zope3-centric future, we would probably do this by registering
subscription adapters for some interface, e.g. (notional only)::

  class ICatalogable:
def items():
""" Return a sequence of key,value pairs for the context.
"""

and then have the indexing machinery use the component architecture to
find all registered adapters for the indexed object.  The indexes and
metadata would then pull from the mapping created by unioning the items
from the subscription adapters.


Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDBn8C+gerLs4ltQ4RAsrsAJ413J39msbacR8U5bL498qFzIcLawCfWD6A
L6w0mil0s4MUwk179sapvj4=
=agSh
-END PGP SIGNATURE-

___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests