--- 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