#
# 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'
# import standard library
# import interfaces
from pyams_content.component.gallery.interfaces import IGallery, IGalleryTarget, IGalleryFile
from pyams_content_es.interfaces import IDocumentIndexInfo
# import packages
from pyams_utils.adapter import adapter_config
[docs]@adapter_config(context=IGallery, provides=IDocumentIndexInfo)
def gallery_index_info(gallery):
"""Gallery index info"""
info = {}
for lang, title in gallery.title.items():
if title:
info.setdefault(lang, title)
for lang, description in gallery.description.items():
if description:
new_info = '{old}\n{info}'.format(old=info.get(lang, ''),
info=description)
info[lang] = new_info
for image in gallery.values():
if IGalleryFile.providedBy(image) and not IGalleryFile(image).visible:
continue
for lang, title in (image.title or {}).items():
if title:
new_info = '{old}\n{info}'.format(old=info.get(lang, ''),
info=title)
info[lang] = new_info
for lang, description in (image.description or {}).items():
if description:
new_info = '{old}\n{info}'.format(old=info.get(lang, ''),
info=description)
info[lang] = new_info
for lang, comments in (image.author_comments or {}).items():
if comments:
new_info = '{old}\n{info}'.format(old=info.get(lang, ''),
info=comments)
info[lang] = new_info
return info
[docs]@adapter_config(name='gallery', context=IGalleryTarget, provides=IDocumentIndexInfo)
def gallery_target_index_info(content):
"""Gallery container index info"""
body = {}
gallery = IGallery(content)
info = IDocumentIndexInfo(gallery, None)
if info is not None:
for lang, info_body in info.items():
body[lang] = '{old}\n{body}'.format(old=body.get(lang, ''),
body=info_body)
return {'gallery': body}