diff -r 000000000000 -r 5af41c7a366f src/pyams_content_es/component/gallery.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content_es/component/gallery.py Thu Apr 21 18:24:52 2016 +0200 @@ -0,0 +1,70 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# 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 IGalleryContainerTarget, IGalleryContainer, IGallery, \ + IGalleryFileInfo +from pyams_content_es.interfaces import IDocumentIndexInfo + +# import packages +from pyams_utils.adapter import adapter_config + + +@adapter_config(context=IGallery, provides=IDocumentIndexInfo) +def GalleryIndexInfo(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(): + image_info = IGalleryFileInfo(image, None) + if image_info is not None: + for lang, title in (image_info.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_info.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_info.author_comments or {}).items(): + if comments: + new_info = '{old}\n{info}'.format(old=info.get(lang, ''), + info=comments) + info[lang] = new_info + return info + + +@adapter_config(name='gallery', context=IGalleryContainerTarget, provides=IDocumentIndexInfo) +def GalleryContainerTargetIndexInfo(content): + """Gallery container index info""" + body = {} + for gallery in IGalleryContainer(content).values(): + 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}