[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/PathIndex - PathIndex.py:1.7

Andreas Jung andreas@zope.com
Wed, 3 Oct 2001 09:04:06 -0400


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/PathIndex
In directory cvs.zope.org:/tmp/cvs-serv6358/lib/python/Products/PluginIndexes/PathIndex

Modified Files:
	PathIndex.py 
Log Message:
      - Objects indexed by the PathIndex can now provide a hook or an 
        attribute with the same name as the index name to provide
        a customized path information other than using getPhysicalPath().



=== Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py 1.6 => 1.7 ===
 from BTrees.OIBTree import OIBTree
 from BTrees.IIBTree import IISet,difference,intersection,union
-from types import StringType
+from types import StringType, ListType, TupleType
 import re,warnings
 
 
@@ -174,12 +174,26 @@
     def index_object(self, documentId, obj ,threshold=100):
         """ hook for (Z)Catalog """
 
-        try:
-            path = obj.getPhysicalPath()
-        except:
-            return 0
 
-        path = '/'+ '/'.join(path[1:])
+        # first we check if the object provide an attribute or
+        # method to be used as hook for the PathIndex
+
+        if hasattr(obj,self.id):
+            f = getattr(obj,self.id)
+            if callable(f):
+                path = f()
+            else:
+                path = f
+        else:             
+
+            try:
+                path = obj.getPhysicalPath()
+            except:
+                return 0
+
+        if type(path) in (ListType,TupleType):
+            path = '/'+ '/'.join(path[1:])
+
         comps = self.splitPath(path,obj)
 
         if obj.meta_type != 'Folder':