src/pyams_content/component/paragraph/zmi/preview.py
branchdev-dc
changeset 1086 3d259e1718ef
parent 1079 a5e56749ca3d
parent 1084 6b6a884fa28a
child 1087 978a2b9123b9
equal deleted inserted replaced
1079:a5e56749ca3d 1086:3d259e1718ef
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \
       
    20     IParagraphRenderer
       
    21 from pyams_content.features.renderer.interfaces import ISharedContentRenderer
       
    22 from pyams_skin.layer import IPyAMSLayer
       
    23 
       
    24 # import packages
       
    25 from pyams_content.features.renderer.skin import BaseContentRenderer
       
    26 from pyams_utils.adapter import adapter_config
       
    27 
       
    28 
       
    29 @adapter_config(name='paragraphs-render', context=(IParagraphContainerTarget, IPyAMSLayer),
       
    30                 provides=ISharedContentRenderer)
       
    31 class ParagraphsContainerRenderer(BaseContentRenderer):
       
    32     """Paragraphs container renderer"""
       
    33 
       
    34     weight = 10
       
    35 
       
    36     def __init__(self, context, request):
       
    37         super(ParagraphsContainerRenderer, self).__init__(context, request)
       
    38         paragraphs = [para for para in IParagraphContainer(self.context).values()
       
    39                       if para.visible]
       
    40         registry = self.request.registry
       
    41         self.renderers = [registry.queryMultiAdapter((paragraph, self.request), IParagraphRenderer)
       
    42                           for paragraph in paragraphs]
       
    43 
       
    44     def update(self):
       
    45         super(ParagraphsContainerRenderer, self).update()
       
    46         for renderer in self.renderers:
       
    47             if renderer is not None:
       
    48                 renderer.language = self.language
       
    49                 renderer.update()
       
    50 
       
    51     def render(self):
       
    52         result = ''
       
    53         for renderer in self.renderers:
       
    54             if renderer is not None:
       
    55                 result += renderer.render()
       
    56         return result