helper function to build the recursive list of broader keywords (#4570)

This commit is contained in:
Frédéric Péters 2014-03-31 11:08:05 +02:00
parent 85f0820005
commit 101c84d801
1 changed files with 10 additions and 0 deletions

View File

@ -76,6 +76,16 @@ class DmsKeyword(Item):
words.append(keyword.get_words_for_indexation(limit=limit-1))
return ' '.join(words)
def get_keyword_tree(self, limit=5):
thesaurus = aq_parent(self)
l = [self.id]
for broader_keyword in self.broader or []:
try:
keyword = thesaurus[broader_keyword]
except KeyError:
continue
l.extend(keyword.get_keyword_tree(limit=limit-1))
return l
class DmsKeywordSchemaPolicy(DexteritySchemaPolicy):