# HG changeset patch # User Thierry Florac # Date 1435666792 -7200 # Node ID 6a22cec2899bc80c90b85ab06f2b7ff71c9a9860 # Parent 9f3987a2dd72250516a8d9a375b7a77b3708172d Added "extract" argument to "get_top_terms" method diff -r 9f3987a2dd72 -r 6a22cec2899b src/pyams_thesaurus/interfaces/thesaurus.py --- a/src/pyams_thesaurus/interfaces/thesaurus.py Wed Jun 17 10:01:13 2015 +0200 +++ b/src/pyams_thesaurus/interfaces/thesaurus.py Tue Jun 30 14:19:52 2015 +0200 @@ -90,6 +90,9 @@ def reset_terms_parent(self): """Reset thesaurus terms parent attribute""" + def get_top_terms(self, extract=None): + """Get top terms, for given extract or for the whole thesaurus""" + def reset_top_terms(self): """Reset thesaurus top terms""" diff -r 9f3987a2dd72 -r 6a22cec2899b src/pyams_thesaurus/thesaurus.py --- a/src/pyams_thesaurus/thesaurus.py Wed Jun 17 10:01:13 2015 +0200 +++ b/src/pyams_thesaurus/thesaurus.py Tue Jun 30 14:19:52 2015 +0200 @@ -115,7 +115,6 @@ self.reset_terms_parent() self.reset_top_terms() - @property def sublocations(self): return self.terms, self.catalog @@ -128,7 +127,9 @@ self._top_terms = [term for term in value or () if term.usage is None] def init_catalog(self): + # Init catalog catalog = self.catalog = Catalog() + locate(catalog, self) # Init fulltext search catalog catalog['fulltext'] = TextIndexWithInterface(IThesaurusTerm, 'label', language=self.language) # Init stemmed search catalog @@ -202,6 +203,11 @@ self.top_terms = [term for term in self.terms.values() if (not term.generic) and (not term.usage)] + def get_top_terms(self, extract=None): + if extract is None: + return self.top_terms + return [term for term in self.top_terms if extract in term.extracts] + def clear(self): self.terms.clear() self.catalog.reset()