From b0a6728927d3d3a130293316ba0f442388f37179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 24 Nov 2011 13:22:20 +0100 Subject: [PATCH] exclude self from related elements --- tabellio/documents/common.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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]