# HG changeset patch # User Thierry Florac # Date 1520850881 -3600 # Node ID 5c673448b942d1cd3682e40d8c1e6e06f91e421b # Parent 38115f8aa6148a7ab971855434796060b4e77597 Updated index adapters for new paragraph types diff -r 38115f8aa614 -r 5c673448b942 src/pyams_content_es/component/extfile.py --- a/src/pyams_content_es/component/extfile.py Sun Mar 11 11:23:21 2018 +0100 +++ b/src/pyams_content_es/component/extfile.py Mon Mar 12 11:34:41 2018 +0100 @@ -17,7 +17,7 @@ import base64 # import interfaces -from pyams_content.component.association.interfaces import IAssociationContainer +from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationItem from pyams_content.component.extfile.interfaces import IBaseExtFile from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer from pyams_content_es.interfaces import IDocumentIndexInfo @@ -34,6 +34,8 @@ for paragraph in IParagraphContainer(context).values(): associations = IAssociationContainer(paragraph, {}) for extfile in associations.values(): + if not IAssociationItem(extfile).visible: + continue if not (IBaseExtFile.providedBy(extfile) and extfile.data): continue extfiles.append({'title': extfile.title, diff -r 38115f8aa614 -r 5c673448b942 src/pyams_content_es/component/gallery.py --- a/src/pyams_content_es/component/gallery.py Sun Mar 11 11:23:21 2018 +0100 +++ b/src/pyams_content_es/component/gallery.py Mon Mar 12 11:34:41 2018 +0100 @@ -16,7 +16,7 @@ # import standard library # import interfaces -from pyams_content.component.gallery.interfaces import IGallery, IGalleryTarget +from pyams_content.component.gallery.interfaces import IGallery, IGalleryTarget, IGalleryFile from pyams_content_es.interfaces import IDocumentIndexInfo # import packages @@ -36,6 +36,8 @@ 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, ''), diff -r 38115f8aa614 -r 5c673448b942 src/pyams_content_es/component/paragraph.py --- a/src/pyams_content_es/component/paragraph.py Sun Mar 11 11:23:21 2018 +0100 +++ b/src/pyams_content_es/component/paragraph.py Mon Mar 12 11:34:41 2018 +0100 @@ -9,6 +9,15 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # +from pyams_content.component.paragraph import IBaseParagraph +from pyams_content.component.paragraph.interfaces.contact import IContactParagraph +from pyams_content.component.paragraph.interfaces.frame import IFrameParagraph +from pyams_content.component.paragraph.interfaces.keypoint import IKeypointsParagraph +from pyams_content.component.paragraph.interfaces.verbatim import IVerbatimParagraph +from pyams_content.component.paragraph.interfaces.video import IVideoParagraph +from pyams_content.component.video.interfaces import IExternalVideoParagraph +from pyams_i18n.interfaces import II18nManager +from pyams_utils.traversing import get_parent __docformat__ = 'restructuredtext' @@ -20,7 +29,7 @@ from pyams_content.component.illustration.interfaces import IIllustrationParagraph from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget from pyams_content.component.paragraph.interfaces.header import IHeaderParagraph -from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph +from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph, IRawParagraph from pyams_content.shared.imagemap.interfaces import IImageMapParagraph from pyams_content_es.interfaces import IDocumentIndexInfo @@ -29,6 +38,31 @@ from pyams_utils.html import html_to_text +@adapter_config(name='body', context=IParagraphContainerTarget, provides=IDocumentIndexInfo) +def ParagraphContainerTargetIndexInfo(content): + """Paragraph container index info""" + body = {} + for paragraph in IParagraphContainer(content).values(): + if not paragraph.visible: + continue + info = IDocumentIndexInfo(paragraph, 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 {'body': body} + + +@adapter_config(context=IBaseParagraph, provides=IDocumentIndexInfo) +def BaseParagraphIndexInfo(paragraph): + """Base paragraph index info""" + info = {} + for lang, title in (getattr(paragraph, 'title', {}) or {}).items(): + if title: + info.setdefault(lang, title) + return info + + @adapter_config(context=IHeaderParagraph, provides=IDocumentIndexInfo) def HeaderParagraphIndexInfo(paragraph): """Header paragraph index info""" @@ -41,7 +75,7 @@ @adapter_config(context=IHTMLParagraph, provides=IDocumentIndexInfo) def HTMLParagraphIndexInfo(paragraph): - """HTML paragraph index info""" + """Rich text paragraph index info""" info = {} for lang, title in (getattr(paragraph, 'title', {}) or {}).items(): if title: @@ -86,6 +120,52 @@ return info +@adapter_config(context=IVideoParagraph, provides=IDocumentIndexInfo) +def VideoParagraphIndexInfo(paragraph): + """Video paragraph index info""" + info = {} + manager = get_parent(paragraph, II18nManager) + for lang in manager.get_languages(): + body = (paragraph.body or {}).get(lang, '') + if body: + info[lang] = '{old}\n{body}'.format(old=info.get(lang, ''), + body=html_to_text(body.replace('\r', ''))) + for attr in ('title', 'description'): + value = getattr(paragraph, attr, {}).get(lang, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + for attr in ('author', ): + value = getattr(paragraph, attr, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + return info + + +@adapter_config(context=IExternalVideoParagraph, provides=IDocumentIndexInfo) +def ExternalVideoParagraphIndexInfo(paragraph): + """External video paragraph index info""" + info = {} + manager = get_parent(paragraph, II18nManager) + for lang in manager.get_languages(): + body = (paragraph.body or {}).get(lang, '') + if body: + info[lang] = '{old}\n{body}'.format(old=info.get(lang, ''), + body=html_to_text(body.replace('\r', ''))) + for attr in ('title', 'description'): + value = getattr(paragraph, attr, {}).get(lang, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + for attr in ('author',): + value = getattr(paragraph, attr, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + return info + + @adapter_config(context=IImageMapParagraph, provides=IDocumentIndexInfo) def ImagemapParagraphIndexInfo(paragraph): """Image map paragraph index info""" @@ -96,14 +176,78 @@ return info -@adapter_config(name='body', context=IParagraphContainerTarget, provides=IDocumentIndexInfo) -def ParagraphContainerTargetIndexInfo(content): - """Paragraph container index info""" - body = {} - for paragraph in IParagraphContainer(content).values(): - info = IDocumentIndexInfo(paragraph, 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 {'body': body} +@adapter_config(context=IContactParagraph, provides=IDocumentIndexInfo) +def ContactParagraphIndexInfo(paragraph): + """Contact paragraph index info""" + info = {} + manager = get_parent(paragraph, II18nManager) + for lang in manager.get_languages(): + for attr in ('title', 'charge'): + value = getattr(paragraph, attr, {}).get(lang, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + for attr in ('name', 'address'): + value = getattr(paragraph, attr, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + return info + + +@adapter_config(context=IKeypointsParagraph, provides=IDocumentIndexInfo) +def KeypointsParagraphIndexInfo(paragraph): + """Key points paragraph index info""" + info = {} + for lang, body in (getattr(paragraph, 'body', {}) or {}).items(): + if body: + info.setdefault(lang, body) + return info + + +@adapter_config(context=IFrameParagraph, provides=IDocumentIndexInfo) +def FrameParagraphIndexInfo(paragraph): + """Frame paragraph index info""" + info = {} + for lang, title in (getattr(paragraph, 'title', {}) or {}).items(): + if title: + info.setdefault(lang, title) + for lang, body in (getattr(paragraph, 'body', {}) or {}).items(): + if body: + info[lang] = '{old}\n{body}'.format(old=info.get(lang, ''), + body=html_to_text(body.repplace('\r', ''))) + return info + + +@adapter_config(context=IVerbatimParagraph, provides=IDocumentIndexInfo) +def VerbatimParagraphIndexInfo(paragraph): + """Verbatim paragraph index info""" + info = {} + manager = get_parent(paragraph, II18nManager) + for lang in manager.get_languages(): + for attr in ('title', 'quote', 'charge'): + value = getattr(paragraph, attr, {}).get(lang, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + for attr in ('author', ): + value = getattr(paragraph, attr, '') + if value: + info[lang] = '{old}\n{value}'.format(old=info.get(lang, ''), + value=value) + return info + + +@adapter_config(context=IRawParagraph, provides=IDocumentIndexInfo) +def RawParagraphIndexInfo(paragraph): + """Raw paragraph index info""" + info = {} + for lang, title in (getattr(paragraph, 'title', {}) or {}).items(): + if title: + info.setdefault(lang, title) + for lang, body in (getattr(paragraph, 'body', {}) or {}).items(): + if body: + new_body = '{old}\n{body}'.format(old=info.get(lang, ''), + body=html_to_text(body).replace('\r', '')) + info[lang] = new_body + return info