src/pyams_content_es/component/theme.py
changeset 0 5af41c7a366f
child 3 bfd1096fd666
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content_es/component/theme.py	Thu Apr 21 18:24:52 2016 +0200
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+from pyams_utils.list import unique
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.component.theme.interfaces import IThemesTarget, IThemesInfo
+from pyams_content_es.interfaces import IDocumentIndexInfo
+
+# import packages
+from pyams_utils.adapter import adapter_config
+
+
+@adapter_config(name='themes', context=IThemesTarget, provides=IDocumentIndexInfo)
+def ThemesTargetIndexInfo(content):
+    """Themes target index info"""
+    terms = []
+    parents = []
+    synonyms = []
+    associations = []
+    for term in IThemesInfo(content).themes or ():
+        terms.append(term.label)
+        if term.usage is not None:
+            terms.append(term.usage.label)
+        parents.extend([parent.label for parent in term.get_parents()])
+        synonyms.extend([synonym.label for synonym in term.used_for])
+        associations.extend([association.label for association in term.associations])
+    return {'themes': {'terms': unique(terms),
+                       'parents': unique(parents),
+                       'synonyms': unique(synonyms),
+                       'associations': unique(associations)}}