exclude self from related elements

This commit is contained in:
Frédéric Péters 2011-11-24 13:22:20 +01:00
parent 25ad8571fa
commit b0a6728927
1 changed files with 7 additions and 3 deletions

View File

@ -44,6 +44,7 @@ class BasePublication(object):
# try to get other elements sharing the same topics
catalog = getToolByName(self, 'portal_catalog')
previous_result = None
r = []
while len(topics) > len(self.topics)*closeness:
brains = catalog(portal_type=self.portal_type,
topics={'query': topics, 'operator': 'and'})
@ -52,9 +53,12 @@ class BasePublication(object):
random.shuffle(brains)
if previous_result:
brains = list(previous_result) + brains
return brains[:max_items]
r = brains[:max_items]
break
elif len(brains) > max_items/2:
return brains
r = brains
break
previous_result = brains
del topics[random.randint(0, len(topics)-1)]
return []
doc_ids = [self.context.id]
return [x for x in r if ((type(x.getId) is str) and x.getId or x.getId()) not in doc_ids]