# HG changeset patch # User Thierry Florac # Date 1531230384 -7200 # Node ID 6eaae503e35d361a15dd578659be139a3fdbdfb2 # Parent fcb43af4eccd097ea575c66521b971f12ec0343b Added widget factory displaying all selectable terms tree diff -r fcb43af4eccd -r 6eaae503e35d src/pyams_thesaurus/widget/__init__.py --- a/src/pyams_thesaurus/widget/__init__.py Mon Jul 09 13:43:31 2018 +0200 +++ b/src/pyams_thesaurus/widget/__init__.py Tue Jul 10 15:46:24 2018 +0200 @@ -172,6 +172,32 @@ return FieldWidget(field, ThesaurusTermsListWidget(request)) +@widgettemplate_config(mode='input', template='templates/terms-tree-input.pt', layer=IFormLayer) +class ThesaurusTermsTreeWidget(ThesaurusTermsListWidget): + """Thesaurus terms tree widget""" + + @property + def top_terms(self): + thesaurus = query_utility(IThesaurus, name=self.thesaurus_name) + if thesaurus is not None: + return sorted(thesaurus.get_top_terms(extract=self.extract_name), + key=lambda x: x.label) + else: + return () + + def get_subterms(self, term): + for subterm in term.specifics: + if (not self.extract_name) or (self.extract_name in subterm.extracts): + yield subterm + for another in self.get_subterms(subterm): + yield another + + +def ThesaurusTermsTreeFieldWidget(field, request): + """Thesaurus terms tree field widget factory""" + return FieldWidget(field, ThesaurusTermsTreeWidget(request)) + + # # Terms list widget with selector # diff -r fcb43af4eccd -r 6eaae503e35d src/pyams_thesaurus/widget/templates/terms-tree-input.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_thesaurus/widget/templates/terms-tree-input.pt Tue Jul 10 15:46:24 2018 +0200 @@ -0,0 +1,32 @@ + +
+
+
+

+
+
+ +
+ +
+
+
+
+
+