diff --git a/tabellio/documents/common.py b/tabellio/documents/common.py index 52ed1c7..111def3 100644 --- a/tabellio/documents/common.py +++ b/tabellio/documents/common.py @@ -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]