[Zope3-checkins] CVS: Zope3/src/zope/app/index/field - index.py:1.7
Marius Gedminas
mgedmin@codeworks.lt
Mon, 23 Jun 2003 12:45:09 -0400
Update of /cvs-repository/Zope3/src/zope/app/index/field
In directory cvs.zope.org:/tmp/cvs-serv9136/src/zope/app/index/field
Modified Files:
index.py
Log Message:
FieldIndex now can adapt objects to a specific interface before indexing them.
For example, now you can create an index that adapts objects to IZopeDublinCore
and indexes their 'title' attributes.
=== Zope3/src/zope/app/index/field/index.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/index/field/index.py:1.6 Sun Jun 22 12:08:14 2003
+++ Zope3/src/zope/app/index/field/index.py Mon Jun 23 12:44:38 2003
@@ -21,7 +21,7 @@
$Id$
"""
-from zope.component import getService
+from zope.component import getService, queryAdapter
from zope.app.services.servicenames import HubIds
from zope.context import ContextMethod
from zope.app.interfaces.event import ISubscriber
@@ -40,14 +40,22 @@
implements(ISubscriber, IUIFieldIndex)
- def __init__(self, indexed_attr):
+ def __init__(self, field_name, interface=None):
FieldIndexWrapper.__init__(self)
- self._indexed_attr = indexed_attr
+ self._field_name = field_name
+ self._interface = interface
+
+ field_name = property(lambda self: self._field_name)
+ interface = property(lambda self: self._interface)
def _getValue(self, object):
- value = getattr(object, self._indexed_attr, None)
+ if self._interface is not None:
+ object = queryAdapter(object, self._interface)
+ if object is None: return None
+
+ value = getattr(object, self._field_name, None)
if value is None: return None
if callable(value):