Merge branch dev-dc
authorThierry Florac <thierry.florac@onf.fr>
Tue, 04 Dec 2018 16:42:34 +0100
changeset 277 4064779f9ab0
parent 273 7e42b94d188e (current diff)
parent 276 283807967468 (diff)
child 278 2ff610b16c86
Merge branch dev-dc
src/pyams_default_theme/component/association/__init__.py
src/pyams_default_theme/component/association/interfaces/__init__.py
--- a/src/pyams_default_theme/component/association/__init__.py	Tue Dec 04 15:12:38 2018 +0100
+++ b/src/pyams_default_theme/component/association/__init__.py	Tue Dec 04 16:42:34 2018 +0100
@@ -12,6 +12,8 @@
 
 __docformat__ = 'restructuredtext'
 
+from itertools import islice
+
 from persistent import Persistent
 from zope.interface import implementer
 from zope.location import Location
@@ -23,7 +25,8 @@
 from pyams_content.component.links.interfaces import IBaseLink, IInternalLink
 from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget
 from pyams_content.features.renderer.interfaces import IContentRenderer
-from pyams_default_theme.component.association.interfaces import IAssociationParagraphRemoteContentRendererSettings
+from pyams_default_theme.component.association.interfaces import IAssociationParagraphRemoteContentRendererSettings, \
+    IAssociationParagraphSlicedRemoteContentRendererSettings
 from pyams_default_theme.features.renderer import BaseContentRenderer
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
@@ -69,9 +72,55 @@
 # Associations paragraph remote content renderer
 #
 
+ASSOCIATION_PARAGRAPH_SLICED_REMOTE_CONTENT_RENDERER_SETTINGS_KEY = 'pyams_content.association.renderer:sliced-remote-content'
 ASSOCIATION_PARAGRAPH_REMOTE_CONTENT_RENDERER_SETTINGS_KEY = 'pyams_content.association.renderer:remote-content'
 
 
+@implementer(IAssociationParagraphSlicedRemoteContentRendererSettings)
+class AssociationParagraphSlicedRemoteContentRendererSettings(Persistent, Location):
+    """Associations paragraph sliced remote content renderer settings"""
+
+    display_title = FieldProperty(IAssociationParagraphSlicedRemoteContentRendererSettings['display_title'])
+    display_header = FieldProperty(IAssociationParagraphSlicedRemoteContentRendererSettings['display_header'])
+    paragraphs_count = FieldProperty(IAssociationParagraphSlicedRemoteContentRendererSettings['paragraphs_count'])
+
+
+@adapter_config(context=IAssociationParagraph, provides=IAssociationParagraphSlicedRemoteContentRendererSettings)
+def association_paragraph_sliced_remote_content_renderer_settings_factory(context):
+    """Associations paragraph sliced remote content renderer settings factory"""
+    return get_annotation_adapter(context, ASSOCIATION_PARAGRAPH_SLICED_REMOTE_CONTENT_RENDERER_SETTINGS_KEY,
+                                  AssociationParagraphSlicedRemoteContentRendererSettings)
+
+
+@adapter_config(name='reportage', context=(IAssociationParagraph, IPyAMSLayer), provides=IContentRenderer)
+@template_config(template='templates/association-remote-content.pt', layer=IPyAMSLayer)
+class AssociationParagraphSlicedRemoteContentRenderer(BaseContentRenderer):
+    """Associations container sliced remote content renderer"""
+
+    label = _("Include first remote content paragraphs")
+    weight = 10
+
+    i18n_context_attrs = ('title',)
+    links = ()
+
+    settings_interface = IAssociationParagraphSlicedRemoteContentRendererSettings
+
+    def update(self):
+        super(AssociationParagraphSlicedRemoteContentRenderer, self).update()
+        self.links = [item for item in IAssociationContainer(self.context).get_visible_items(self.request)
+                      if IInternalLink.providedBy(item) and IParagraphContainerTarget.providedBy(item.target)]
+
+    def get_renderers(self, target):
+        container = IParagraphContainer(target, None)
+        if container is not None:
+            for renderer in islice(map(lambda x: x.get_renderer(self.request),
+                                       container.get_visible_paragraphs()),
+                                   self.settings.paragraphs_count):
+                if renderer is not None:
+                    renderer.update()
+                    yield renderer.render()
+
+
 @implementer(IAssociationParagraphRemoteContentRendererSettings)
 class AssociationParagraphRemoteContentRendererSettings(Persistent, Location):
     """Associations paragraph remote content renderer settings"""
@@ -94,8 +143,8 @@
 class AssociationParagraphRemoteContentRenderer(BaseContentRenderer):
     """Associations container remote content renderer"""
 
-    label = _("Include remote content")
-    weight = 10
+    label = _("Include remote content paragraphs")
+    weight = 11
 
     i18n_context_attrs = ('title',)
     links = ()
--- a/src/pyams_default_theme/component/association/interfaces/__init__.py	Tue Dec 04 15:12:38 2018 +0100
+++ b/src/pyams_default_theme/component/association/interfaces/__init__.py	Tue Dec 04 16:42:34 2018 +0100
@@ -12,19 +12,15 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
+from zope.interface import Interface
+from zope.schema import Bool, Set, Choice, Int
 
-# import packages
-from zope.interface import Interface
-from zope.schema import Bool, Set, Choice
+from pyams_content.component.paragraph.interfaces import PARAGRAPH_FACTORIES_VOCABULARY
 
-# import interfaces
-from pyams_content.component.paragraph.interfaces import PARAGRAPH_FACTORIES_VOCABULARY
 from pyams_default_theme import _
 
 
-class IAssociationParagraphRemoteContentRendererSettings(Interface):
+class IBaseAssociationParagraphRemoteContentRendererSettings(Interface):
     """Associations paragraph remote content renderer settings interface"""
 
     display_title = Bool(title=_("Display title?"),
@@ -37,6 +33,19 @@
                           required=True,
                           default=False)
 
+
+class IAssociationParagraphSlicedRemoteContentRendererSettings(IBaseAssociationParagraphRemoteContentRendererSettings):
+    """Associations paragraph renderer settings interface"""
+
+    paragraphs_count = Int(title=_("Paragraphs count"),
+                           description=_("Number of paragraphs used for each remote content (default=1)"),
+                           required=False,
+                           default=1)
+
+
+class IAssociationParagraphRemoteContentRendererSettings(IBaseAssociationParagraphRemoteContentRendererSettings):
+    """Associations paragraph remote content renderer settings interface"""
+
     factories = Set(title=_("Paragraph types"),
                     description=_("Select list of paragraph types you want to include; an empty "
                                   "selection means that all paragraphs will be selected"),
@@ -46,4 +55,4 @@
     anchors_only = Bool(title=_("Anchors only?"),
                         description=_("If 'yes', only paragraphs set as 'anchors' will be selected"),
                         required=True,
-                        default=True)
+                        default=False)