Commit 68957496 authored by Guido van Rossum's avatar Guido van Rossum

index_object(): don't die if obj doesn't have an attribute named

_fieldname; simply return 0 in this case.
parent 0a97b655
......@@ -92,7 +92,12 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
def index_object(self, docid, obj, threshold=None):
# XXX We currently ignore subtransaction threshold
count = self.index.index_doc(docid, self._get_object_text(obj))
text = getattr(obj, self._fieldname, None)
if text is None:
return 0
if callable(text):
text = text()
count = self.index.index_doc(docid, text)
self._p_changed = 1 # XXX
return count
......@@ -132,15 +137,6 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
"""reinitialize the index"""
self.index = self._index_factory(self.lexicon)
## Helper ##
def _get_object_text(self, obj):
x = getattr(obj, self._fieldname)
if callable(x):
return x()
else:
return x
## User Interface Methods ##
manage_main = DTMLFile('dtml/manageZCTextIndex', globals())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment