Updated frame and verbatim paragraphs renderers
authorThierry Florac <thierry.florac@onf.fr>
Fri, 12 Oct 2018 17:05:26 +0200
changeset 182 f419b942f7f4
parent 181 97e8610cbabd
child 183 f543e56f0d07
Updated frame and verbatim paragraphs renderers
src/pyams_default_theme/component/paragraph/frame.py
src/pyams_default_theme/component/paragraph/html.py
src/pyams_default_theme/component/paragraph/interfaces/frame.py
src/pyams_default_theme/component/paragraph/interfaces/verbatim.py
src/pyams_default_theme/component/paragraph/templates/frame-default.pt
src/pyams_default_theme/component/paragraph/templates/frame-left.pt
src/pyams_default_theme/component/paragraph/templates/frame-right.pt
src/pyams_default_theme/component/paragraph/templates/html-default.pt
src/pyams_default_theme/component/paragraph/templates/verbatim-default.pt
src/pyams_default_theme/component/paragraph/templates/verbatim-left.pt
src/pyams_default_theme/component/paragraph/templates/verbatim-right.pt
src/pyams_default_theme/component/paragraph/verbatim.py
--- a/src/pyams_default_theme/component/paragraph/frame.py	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/frame.py	Fri Oct 12 17:05:26 2018 +0200
@@ -49,17 +49,9 @@
 class BaseFrameParagraphRendererSettings(Persistent, Location):
     """Base frame text paragraph renderer settings"""
 
-    display_illustration = FieldProperty(IFrameParagraphRendererSettings['display_illustration'])
     display_associations = FieldProperty(IFrameParagraphRendererSettings['display_associations'])
     _pictogram_name = FieldProperty(IDefaultFrameParagraphRendererSettings['pictogram_name'])
 
-    def can_display_illustration(self):
-        if not self.display_illustration:
-            return False
-        frame = IFrameParagraph(self.__parent__)
-        illustration = IIllustration(frame, None)
-        return (illustration is not None) and bool(II18n(illustration).query_attribute('data'))
-
     def can_display_associations(self):
         if not self.display_associations:
             return False
@@ -139,8 +131,18 @@
     """Base frame paragraph renderer"""
 
     i18n_context_attrs = ('title', 'body')
+
+    illustration = None
     illustration_renderer = None
 
+    def update(self):
+        super(BaseFrameParagraphRenderer, self).update()
+        self.illustration = IIllustration(self.context)
+        if self.illustration.data:
+            renderer = self.illustration_renderer = self.illustration.get_renderer(self.request)
+            if renderer is not None:
+                renderer.update()
+
 
 @adapter_config(name='default', context=(IFrameParagraph, IPyAMSLayer), provides=IContentRenderer)
 @template_config(template='templates/frame-default.pt', layer=IPyAMSLayer)
--- a/src/pyams_default_theme/component/paragraph/html.py	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/html.py	Fri Oct 12 17:05:26 2018 +0200
@@ -12,20 +12,16 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
 from pyams_content.component.illustration import IIllustration
-from pyams_content.component.paragraph.interfaces.html import IRawParagraph, IHTMLParagraph
+from pyams_content.component.paragraph.interfaces.html import IHTMLParagraph, IRawParagraph
 from pyams_content.features.renderer.interfaces import IContentRenderer
-# import packages
 from pyams_content.features.renderer.skin import BaseContentRenderer
-from pyams_default_theme import _
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 
+from pyams_default_theme import _
+
 
 #
 # Raw paragraph default renderer
@@ -38,7 +34,7 @@
 
     label = _("Default raw HTML renderer")
 
-    i18n_context_attrs = ('title', 'body', )
+    i18n_context_attrs = ('title', 'body',)
 
 
 #
@@ -52,7 +48,7 @@
 
     label = _("Default rich text renderer")
 
-    i18n_context_attrs = ('title', 'body', )
+    i18n_context_attrs = ('title', 'body',)
 
     illustration = None
     illustration_renderer = None
@@ -64,8 +60,3 @@
             renderer = self.illustration_renderer = self.illustration.get_renderer(self.request)
             if renderer is not None:
                 renderer.update()
-
-    def render_illustration(self):
-        if not self.illustration_renderer:
-            return ''
-        return self.illustration_renderer.render()
--- a/src/pyams_default_theme/component/paragraph/interfaces/frame.py	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/interfaces/frame.py	Fri Oct 12 17:05:26 2018 +0200
@@ -34,14 +34,6 @@
 class IFrameParagraphRendererSettings(Interface):
     """Framed paragraph default renderer settings interface"""
 
-    display_illustration = Bool(title=_("Show illustration?"),
-                                description=_("If 'no', illustration will not be displayed"),
-                                required=True,
-                                default=True)
-
-    def can_display_illustration(self):
-        """Check if illustration can be displayed"""
-
     display_associations = Bool(title=_("Show associations?"),
                                 description=_("If 'no', associations will not be displayed"),
                                 required=True,
--- a/src/pyams_default_theme/component/paragraph/interfaces/verbatim.py	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/interfaces/verbatim.py	Fri Oct 12 17:05:26 2018 +0200
@@ -12,14 +12,8 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
-
-# import packages
 from zope.interface import Interface
-from zope.schema import Bool, Choice
+from zope.schema import Choice
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 from pyams_default_theme import _
@@ -34,23 +28,7 @@
                                                for item in FRAME_POSITIONS])
 
 
-class IVerbatimParagraphRendererSettings(Interface):
-    """Verbatim paragraph default renderer settings interface"""
-
-    display_illustration = Bool(title=_("Show illustration?"),
-                                description=_("If 'no', illustration will not be displayed"),
-                                required=True,
-                                default=True)
-
-    def can_display_illustration(self):
-        """Check if illustration can be displayed"""
-
-
-class IDefaultVerbatimParagraphRendererSettings(IVerbatimParagraphRendererSettings):
-    """Verbatim paragraph default renderer settings interface"""
-
-
-class ILateralVerbatimParagraphRendererSettings(IVerbatimParagraphRendererSettings):
+class ILateralVerbatimParagraphRendererSettings(Interface):
     """Verbatim paragraph lateral renderer settings interface"""
 
     relative_width = Choice(title=_("Relative width"),
--- a/src/pyams_default_theme/component/paragraph/templates/frame-default.pt	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/frame-default.pt	Fri Oct 12 17:05:26 2018 +0200
@@ -1,8 +1,15 @@
 <div class="bordered frame padding-10"
-	 tal:define="settings view.settings">
-	<h3 tal:condition="view.title" tal:content="view.title">Title</h3>
-	<div tal:condition="settings.can_display_illustration()"
-		 tal:replace="structure view.illustration_renderer.render() if view.illustration_renderer is not None else None">
-	</div>
+	 tal:define="settings view.settings;
+				 renderer view.illustration_renderer;
+				 position getattr(renderer, 'position', None) if renderer is not None else None;"
+	 tal:switch="position">
+	<tal:var case="'before-title'">${structure:renderer.render())}</tal:var>
+	<h3 tal:condition="view.title and (position != 'before-title')">${view.title}</h3>
+	<tal:var case="'before-body'">${structure:renderer.render()}</tal:var>
 	<p tal:replace="structure view.body">body</p>
+	<tal:var case="'after-body'">${structure:renderer.render()}</tal:var>
+	<div class="clearfix"></div>
+	<tal:if condition="settings.display_associations">
+		${structure:provider:pyams.associations}
+	</tal:if>
 </div>
--- a/src/pyams_default_theme/component/paragraph/templates/frame-left.pt	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/frame-left.pt	Fri Oct 12 17:05:26 2018 +0200
@@ -1,8 +1,16 @@
 <div class="bordered frame padding-10 pull-left"
-	 tal:define="settings view.settings"
-	 tal:attributes="class string:${default} col-md-${settings.relative_width}">
-	<h3 tal:condition="view.title" tal:content="view.title">Title</h3>
-	<img tal:condition="settings.can_display_illustration()"
-		 tal:replace="structure view.illustration_renderer.render() if view.illustration_renderer is not None else None" />
+	 tal:define="settings view.settings;
+				 renderer view.illustration_renderer;
+				 position getattr(renderer, 'position', None) if renderer is not None else None;"
+	 tal:attributes="class string:${default} col-md-${settings.relative_width}"
+	 tal:switch="position">
+	<tal:var case="'before-title'">${structure:renderer.render())}</tal:var>
+	<h3 tal:condition="view.title and (position != 'before-title')">${view.title}</h3>
+	<tal:var case="'before-body'">${structure:renderer.render()}</tal:var>
 	<p tal:replace="structure view.body">body</p>
+	<tal:var case="'after-body'">${structure:renderer.render()}</tal:var>
+	<div class="clearfix"></div>
+	<tal:if condition="settings.display_associations">
+		${structure:provider:pyams.associations}
+	</tal:if>
 </div>
--- a/src/pyams_default_theme/component/paragraph/templates/frame-right.pt	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/frame-right.pt	Fri Oct 12 17:05:26 2018 +0200
@@ -1,8 +1,16 @@
 <div class="bordered frame padding-10 pull-right"
-	 tal:define="settings view.settings"
-	 tal:attributes="class string:${default} col-md-${settings.relative_width}">
-	<h3 tal:condition="view.title" tal:content="view.title">Title</h3>
-	<img tal:condition="settings.can_display_illustration()"
-		 tal:replace="structure view.illustration_renderer.render() if view.illustration_renderer is not None else None" />
+	 tal:define="settings view.settings;
+				 renderer view.illustration_renderer;
+				 position getattr(renderer, 'position', None) if renderer is not None else None;"
+	 tal:attributes="class string:${default} col-md-${settings.relative_width}"
+	 tal:switch="position">
+	<tal:var case="'before-title'">${structure:renderer.render())}</tal:var>
+	<h3 tal:condition="view.title and (position != 'before-title')">${view.title}</h3>
+	<tal:var case="'before-body'">${structure:renderer.render()}</tal:var>
 	<p tal:replace="structure view.body">body</p>
+	<tal:var case="'after-body'">${structure:renderer.render()}</tal:var>
+	<div class="clearfix"></div>
+	<tal:if condition="settings.display_associations">
+		${structure:provider:pyams.associations}
+	</tal:if>
 </div>
--- a/src/pyams_default_theme/component/paragraph/templates/html-default.pt	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/html-default.pt	Fri Oct 12 17:05:26 2018 +0200
@@ -1,11 +1,11 @@
 <tal:var define="renderer view.illustration_renderer;
 				 position getattr(renderer, 'position', None) if renderer is not None else None;"
 		 switch="position">
-	<tal:var case="'before-title'">${structure:view.render_illustration()}</tal:var>
+	<tal:var case="'before-title'">${structure:renderer.render()}</tal:var>
 	<h2 tal:condition="view.title and (position != 'before-title')">${view.title}</h2>
-	<tal:var case="'before-body'">${structure:view.render_illustration()}</tal:var>
+	<tal:var case="'before-body'">${structure:renderer.render()}</tal:var>
 	<div>${structure:tales:html(view.body, 'oid_to_href')}</div>
-	<tal:var case="'after-body'">${structure:view.render_illustration()}</tal:var>
+	<tal:var case="'after-body'">${structure:renderer.render()}</tal:var>
 	<div class="clearfix"></div>
 	${structure:provider:pyams.associations}
 </tal:var>
--- a/src/pyams_default_theme/component/paragraph/templates/verbatim-default.pt	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/verbatim-default.pt	Fri Oct 12 17:05:26 2018 +0200
@@ -1,9 +1,14 @@
 <div class="bordered verbatim padding-20"
 	 tal:define="settings view.settings;
-				 display_illustration settings.can_display_illustration()">
-	<tal:if condition="display_illustration">
+				 illustration tales:pyams_illustration(context);
+				 display_illustration view.can_display_illustration()">
+	<tal:if condition="display_illustration and illustration">
 		<div class="illustration col-md-2"
-			 tal:content="structure view.illustration_renderer.render() if view.illustration_renderer is not None else None">
+			 tal:define="photo i18n:illustration.data;
+						 alt i18n:illustration.alt_title;"
+			 tal:condition="photo">
+			${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
+											 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
 		</div>
 		<div class="author col-md-4">
 			<span tal:content="view.author">Author</span><br />
@@ -14,11 +19,11 @@
 	</tal:if>
 	<tal:if condition="not:display_illustration">
 		<div class="quote"
-			 tal:content="tales:html(view.quote)">Quote</div>
+			 tal:content="structure tales:html(view.quote)">Quote</div>
 		<div class="author">
-			<span tal:content="view.author">Author</span>
-			<tal:if condition="view.charge">&ndash;</tal:if>
-			<span tal:content="view.charge">Charge</span>
+			${view.author}
+			<tal:if condition="view.author and view.charge">, </tal:if>
+			${view.charge}
 		</div>
 	</tal:if>
 </div>
--- a/src/pyams_default_theme/component/paragraph/templates/verbatim-left.pt	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/verbatim-left.pt	Fri Oct 12 17:05:26 2018 +0200
@@ -1,17 +1,31 @@
 <div class="bordered verbatim padding-20 pull-left"
-	 tal:define="settings view.settings"
+	 tal:define="settings view.settings;
+				 illustration tales:pyams_illustration(context);
+				 display_illustration view.can_display_illustration()"
 	 tal:attributes="class string:${default} col-md-${settings.relative_width}">
 	<h3 tal:condition="view.title" tal:content="view.title">Title</h3>
-	<div tal:condition="settings.can_display_illustration()"
-		 tal:replace="structure view.illustration_renderer.render() if view.illustration_renderer is not None else None">
-	</div>
-	<div class="quote"
-		 tal:content="structure tales:html(view.quote)">Quote</div>
-	<div class="author">
-		<span tal:content="view.author">Author</span>
-		<tal:if condition="view.charge">
-			&ndash;
+	<tal:if condition="display_illustration and illustration">
+		<div class="illustration col-md-2"
+			 tal:define="photo i18n:illustration.data;
+						 alt i18n:illustration.alt_title;"
+			 tal:condition="photo">
+			${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
+											 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
+		</div>
+		<div class="author col-md-4">
+			<span tal:content="view.author">Author</span><br />
 			<span tal:content="view.charge">Charge</span>
-		</tal:if>
-	</div>
+		</div>
+		<div class="quote col-md-5"
+			 tal:content="tales:html(view.quote)">Quote</div>
+	</tal:if>
+	<tal:if condition="not:display_illustration">
+		<div class="quote"
+			 tal:content="structure tales:html(view.quote)">Quote</div>
+		<div class="author">
+			${view.author}
+			<tal:if condition="view.author and view.charge">, </tal:if>
+			${view.charge}
+		</div>
+	</tal:if>
 </div>
--- a/src/pyams_default_theme/component/paragraph/templates/verbatim-right.pt	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/verbatim-right.pt	Fri Oct 12 17:05:26 2018 +0200
@@ -1,17 +1,31 @@
 <div class="bordered verbatim padding-20 pull-right"
-	 tal:define="settings view.settings"
+	 tal:define="settings view.settings;
+				 illustration tales:pyams_illustration(context);
+				 display_illustration view.can_display_illustration()"
 	 tal:attributes="class string:${default} col-md-${settings.relative_width}">
 	<h3 tal:condition="view.title" tal:content="view.title">Title</h3>
-	<div tal:condition="settings.can_display_illustration()"
-		 tal:replace="structure view.illustration_renderer.render() if view.illustration_renderer is not None else None">
-	</div>
-	<div class="quote"
-		 tal:content="structure tales:html(view.quote)">Quote</div>
-	<div class="author">
-		<span tal:content="view.author">Author</span>
-		<tal:if condition="view.charge">
-			&ndash;
+	<tal:if condition="display_illustration and illustration">
+		<div class="illustration col-md-2"
+			 tal:define="photo i18n:illustration.data;
+						 alt i18n:illustration.alt_title;"
+			 tal:condition="photo">
+			${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
+											 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
+		</div>
+		<div class="author col-md-4">
+			<span tal:content="view.author">Author</span><br />
 			<span tal:content="view.charge">Charge</span>
-		</tal:if>
-	</div>
+		</div>
+		<div class="quote col-md-5"
+			 tal:content="tales:html(view.quote)">Quote</div>
+	</tal:if>
+	<tal:if condition="not:display_illustration">
+		<div class="quote"
+			 tal:content="structure tales:html(view.quote)">Quote</div>
+		<div class="author">
+			${view.author}
+			<tal:if condition="view.author and view.charge">, </tal:if>
+			${view.charge}
+		</div>
+	</tal:if>
 </div>
--- a/src/pyams_default_theme/component/paragraph/verbatim.py	Fri Oct 12 10:28:46 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/verbatim.py	Fri Oct 12 17:05:26 2018 +0200
@@ -21,8 +21,7 @@
 from pyams_content.component.paragraph.interfaces.verbatim import IVerbatimParagraph
 from pyams_content.features.renderer.interfaces import IContentRenderer
 from pyams_content.features.renderer.skin import BaseContentRenderer
-from pyams_default_theme.component.paragraph.interfaces.verbatim import IDefaultVerbatimParagraphRendererSettings, \
-    ILateralVerbatimParagraphRendererSettings, IVerbatimParagraphRendererSettings
+from pyams_default_theme.component.paragraph.interfaces.verbatim import ILateralVerbatimParagraphRendererSettings
 from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
@@ -32,40 +31,11 @@
 
 
 #
-# Verbatim paragraph default renderer settings
+# Verbatim paragraph lateral renderer settings
 #
 
-VERBATIM_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.verbatim.renderer:default'
-
-
-@implementer(IVerbatimParagraphRendererSettings)
-class BaseVerbatimParagraphRendererSettings(Persistent, Location):
-    """Base frame text paragraph renderer settings"""
-
-    display_illustration = FieldProperty(IVerbatimParagraphRendererSettings['display_illustration'])
-
-    def can_display_illustration(self):
-        if not self.display_illustration:
-            return False
-        frame = IVerbatimParagraph(self.__parent__)
-        illustration = IIllustration(frame, None)
-        return (illustration is not None) and bool(II18n(illustration).query_attribute('data'))
-
-
-@implementer(IDefaultVerbatimParagraphRendererSettings)
-class DefaultVerbatimParagraphRendererSettings(BaseVerbatimParagraphRendererSettings):
-    """Verbatim paragraph lateral renderer settings"""
-
-
-@adapter_config(context=IVerbatimParagraph, provides=IDefaultVerbatimParagraphRendererSettings)
-def default_verbatim_paragraph_renderer_settings_factory(context):
-    """Frame paragraph default renderer settings factory"""
-    return get_annotation_adapter(context, VERBATIM_PARAGRAPH_RENDERER_SETTINGS_KEY,
-                                  DefaultVerbatimParagraphRendererSettings)
-
-
 @implementer(ILateralVerbatimParagraphRendererSettings)
-class LateralVerbatimParagraphRendererSettings(BaseVerbatimParagraphRendererSettings):
+class LateralVerbatimParagraphRendererSettings(Persistent, Location):
     """Verbatim paragraph lateral renderer settings"""
 
     relative_width = FieldProperty(ILateralVerbatimParagraphRendererSettings['relative_width'])
@@ -90,7 +60,11 @@
 
     context_attrs = ('author',)
     i18n_context_attrs = ('title', 'quote', 'charge')
-    illustration_renderer = None
+
+    def can_display_illustration(self):
+        frame = IVerbatimParagraph(self.context)
+        illustration = IIllustration(frame, None)
+        return (illustration is not None) and bool(II18n(illustration).query_attribute('data'))
 
 
 @adapter_config(name='default', context=(IVerbatimParagraph, IPyAMSLayer), provides=IContentRenderer)
@@ -101,8 +75,6 @@
     label = _("Default verbatim renderer")
     weight = 1
 
-    settings_interface = IDefaultVerbatimParagraphRendererSettings
-
 
 @adapter_config(name='left', context=(IVerbatimParagraph, IPyAMSLayer), provides=IContentRenderer)
 @template_config(template='templates/verbatim-left.pt', layer=IPyAMSLayer)