src/pyams_content_es/component/paragraph.py
changeset 23 35cf2c00874c
parent 20 ea4bfc8f6278
child 26 76977fecfcbf
equal deleted inserted replaced
22:8c7790dd5596 23:35cf2c00874c
    14 
    14 
    15 
    15 
    16 # import standard library
    16 # import standard library
    17 
    17 
    18 # import interfaces
    18 # import interfaces
       
    19 from pyams_content.component.gallery.interfaces import IGalleryParagraph
    19 from pyams_content.component.illustration.interfaces import IIllustrationParagraph
    20 from pyams_content.component.illustration.interfaces import IIllustrationParagraph
    20 from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget
    21 from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget
    21 from pyams_content.component.paragraph.interfaces.header import IHeaderParagraph
    22 from pyams_content.component.paragraph.interfaces.header import IHeaderParagraph
    22 from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph
    23 from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph
       
    24 from pyams_content.shared.imagemap.interfaces import IImageMapParagraph
    23 from pyams_content_es.interfaces import IDocumentIndexInfo
    25 from pyams_content_es.interfaces import IDocumentIndexInfo
    24 
    26 
    25 # import packages
    27 # import packages
    26 from pyams_utils.adapter import adapter_config
    28 from pyams_utils.adapter import adapter_config
    27 from pyams_utils.html import html_to_text
    29 from pyams_utils.html import html_to_text
    65                                                   legend=legend)
    67                                                   legend=legend)
    66             info[lang] = new_legend
    68             info[lang] = new_legend
    67     return info
    69     return info
    68 
    70 
    69 
    71 
       
    72 @adapter_config(context=IGalleryParagraph, provides=IDocumentIndexInfo)
       
    73 def GalleryParagraphIndexInfo(paragraph):
       
    74     """Gallery paragraph index info"""
       
    75     info = {}
       
    76     for lang, title in paragraph.title.items():
       
    77         if title:
       
    78             info.setdefault(lang, title)
       
    79     for image in IGalleryParagraph(paragraph).values():
       
    80         for attr in ('title', 'alt_title', 'description', 'author', 'author_comments', 'sound_title',
       
    81                      'sound_description'):
       
    82             for lang, value in (getattr(image, attr, {}) or {}).items():
       
    83                 if value:
       
    84                     new_info = '{old}\n{value}'.format(old=info.get(lang, ''),
       
    85                                                        value=value or '')
       
    86                     info[lang] = new_info
       
    87     return info
       
    88 
       
    89 
       
    90 @adapter_config(context=IImageMapParagraph, provides=IDocumentIndexInfo)
       
    91 def ImagemapParagraphIndexInfo(paragraph):
       
    92     """Image map paragraph index info"""
       
    93     info = {}
       
    94     for lang, title in paragraph.title.items():
       
    95         if title:
       
    96             info.setdefault(lang, title)
       
    97     return info
       
    98 
       
    99 
    70 @adapter_config(name='body', context=IParagraphContainerTarget, provides=IDocumentIndexInfo)
   100 @adapter_config(name='body', context=IParagraphContainerTarget, provides=IDocumentIndexInfo)
    71 def ParagraphContainerTargetIndexInfo(content):
   101 def ParagraphContainerTargetIndexInfo(content):
    72     """Paragraph container index info"""
   102     """Paragraph container index info"""
    73     body = {}
   103     body = {}
    74     for paragraph in IParagraphContainer(content).values():
   104     for paragraph in IParagraphContainer(content).values():