#
# 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.
#
__docformat__ = 'restructuredtext'
from zope.intid.interfaces import IIntIds
from pyams_content.component.theme import ICollectionsInfo, ICollectionsTarget
from pyams_content.component.theme.interfaces import ITagsInfo, ITagsTarget, IThemesInfo, IThemesTarget
from pyams_content_es.interfaces import IDocumentIndexInfo
from pyams_utils.adapter import adapter_config
from pyams_utils.list import unique
from pyams_utils.registry import get_utility
#
# Tags index
#
#
# Themes index
#
[docs]@adapter_config(name='themes', context=IThemesTarget, provides=IDocumentIndexInfo)
def themes_target_index_info(content):
"""Themes target index info"""
terms = []
parents = []
synonyms = []
associations = []
intids = get_utility(IIntIds)
for term in IThemesInfo(content).themes or ():
terms.append(term)
if term.usage is not None:
terms.append(term.usage)
parents.extend(term.get_parents())
synonyms.extend(term.used_for)
associations.extend(term.associations)
return {
'themes': {
'terms': [intids.register(term) for term in unique(terms)],
'parents': [intids.register(term) for term in unique(parents)],
'synonyms': [intids.register(term) for term in unique(synonyms)],
'associations': [intids.register(term) for term in unique(associations)]
}
}
#
# Collections index
#
[docs]@adapter_config(name='collections', context=ICollectionsTarget, provides=IDocumentIndexInfo)
def collections_target_index_info(content):
"""Collections target index info"""
intids = get_utility(IIntIds)
collections = ICollectionsInfo(content).collections or ()
return {
'collections': [intids.register(tag) for tag in unique(collections)]
}