Merge branch dev-dc
authorThierry Florac <thierry.florac@onf.fr>
Tue, 04 Dec 2018 16:42:34 +0100
changeset 277 4064779f9ab0
parent 273 7e42b94d188e (diff)
parent 276 283807967468 (current 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 16:13:43 2018 +0100
+++ b/src/pyams_default_theme/component/association/__init__.py	Tue Dec 04 16:42:34 2018 +0100
@@ -9,10 +9,11 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from itertools import islice
 
 __docformat__ = 'restructuredtext'
 
+from itertools import islice
+
 from persistent import Persistent
 from zope.interface import implementer
 from zope.location import Location
@@ -71,8 +72,53 @@
 # 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'
-ASSOCIATION_PARAGRAPH_SLICED_REMOTE_CONTENT_RENDERER_SETTINGS_KEY = 'pyams_content.association.renderer:remote-content-sliced'
+
+
+@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)
@@ -85,15 +131,6 @@
     anchors_only = FieldProperty(IAssociationParagraphRemoteContentRendererSettings['anchors_only'])
 
 
-@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'])
-    display_n_paragraphs = FieldProperty(IAssociationParagraphSlicedRemoteContentRendererSettings['display_n_paragraphs'])
-
-
 @adapter_config(context=IAssociationParagraph, provides=IAssociationParagraphRemoteContentRendererSettings)
 def association_paragraph_remote_content_renderer_settings_factory(context):
     """Associations paragraph remote content renderer settings factory"""
@@ -106,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 = ()
@@ -128,41 +165,3 @@
                 if renderer is not None:
                     renderer.update()
                     yield renderer.render()
-
-
-@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 slice remote content")
-    weight = 11
-
-    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:
-            settings = self.settings
-            n = settings.display_n_paragraphs
-            for renderer in islice(map(lambda x: x.get_renderer(self.request),
-                                    container.get_visible_paragraphs()), n):
-                if renderer is not None:
-                    renderer.update()
-                    yield renderer.render()
-
--- a/src/pyams_default_theme/component/association/interfaces/__init__.py	Tue Dec 04 16:13:43 2018 +0100
+++ b/src/pyams_default_theme/component/association/interfaces/__init__.py	Tue Dec 04 16:42:34 2018 +0100
@@ -12,15 +12,11 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import packages
 from zope.interface import Interface
 from zope.schema import Bool, Set, Choice, Int
 
-# import interfaces
 from pyams_content.component.paragraph.interfaces import PARAGRAPH_FACTORIES_VOCABULARY
+
 from pyams_default_theme import _
 
 
@@ -39,12 +35,12 @@
 
 
 class IAssociationParagraphSlicedRemoteContentRendererSettings(IBaseAssociationParagraphRemoteContentRendererSettings):
-    """Associations paragraph special reportage content renderer settings interface"""
+    """Associations paragraph renderer settings interface"""
 
-    display_n_paragraphs = Int(title=_("N first paragraphs"),
-                               description=_("Select the N first paragraphs found for each remote content (default: N=1)"),
-                               required=False,
-                               default=1)
+    paragraphs_count = Int(title=_("Paragraphs count"),
+                           description=_("Number of paragraphs used for each remote content (default=1)"),
+                           required=False,
+                           default=1)
 
 
 class IAssociationParagraphRemoteContentRendererSettings(IBaseAssociationParagraphRemoteContentRendererSettings):