[gen] Indexing machinery: bugfixes (Ref index).

This commit is contained in:
Gaetan Delannay 2012-09-26 23:32:57 +02:00
parent 8d1a88bd27
commit 3bd66e3264

View file

@ -1916,22 +1916,21 @@ class Ref(Type):
def getFormattedValue(self, obj, value): def getFormattedValue(self, obj, value):
return value return value
def getIndexType(self): return 'TextIndex' def getIndexType(self): return 'ListIndex'
def getIndexValue(self, obj, forSearch=False): def getIndexValue(self, obj, forSearch=False):
'''Value for indexing is the list of UIDs of linked objects. If '''Value for indexing is the list of UIDs of linked objects. If
p_forSearch is True, it will return a "string" version made of the p_forSearch is True, it will return a list of the linked objects'
titles of linked objects.''' titles instead.'''
if not forSearch: if not forSearch:
res = getattr(obj.aq_base, self.name, '') res = getattr(obj.aq_base, self.name, [])
if res: res = ' '.join(res) if res:
# The index does not like persistent lists.
res = list(res)
return res return res
else: else:
# For the global search: concatenate titles of linked objects # For the global search: return linked objects' titles.
titles = [] return [o.title for o in self.getValue(type='objects')]
for obj in self.getValue(type='objects'):
titles.append(obj.title)
return ' '.join(titles)
def validateValue(self, obj, value): def validateValue(self, obj, value):
if not self.link: return None if not self.link: return None