Merge branch dev-dc
authorThierry Florac <thierry.florac@onf.fr>
Fri, 12 Oct 2018 10:28:46 +0200
changeset 181 97e8610cbabd
parent 177 610811d72a10 (current diff)
parent 180 e5d91569642f (diff)
child 182 f419b942f7f4
Merge branch dev-dc
src/pyams_default_theme/component/association/__init__.py
src/pyams_default_theme/component/association/templates/association-default.pt
src/pyams_default_theme/component/association/templates/association-viewlet.pt
src/pyams_default_theme/component/association/viewlet.py
src/pyams_default_theme/component/paragraph/templates/html-default.pt
--- a/src/pyams_default_theme/component/association/__init__.py	Thu Oct 11 14:51:45 2018 +0200
+++ b/src/pyams_default_theme/component/association/__init__.py	Fri Oct 12 10:28:46 2018 +0200
@@ -12,28 +12,25 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import packages
 from persistent import Persistent
 from zope.interface import implementer
 from zope.location import Location
 from zope.schema.fieldproperty import FieldProperty
 
-# import interfaces
-from pyams_content.component.association.interfaces import IAssociationParagraph, IAssociationInfo, \
-    IAssociationContainer
-from pyams_content.component.links.interfaces import IInternalLink
-from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer
+from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationInfo, \
+    IAssociationParagraph
+from pyams_content.component.extfile import IExtFile
+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_content.features.renderer.skin import BaseContentRenderer
-from pyams_default_theme import _
 from pyams_default_theme.component.association.interfaces import IAssociationParagraphRemoteContentRendererSettings
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config, get_annotation_adapter
 
+from pyams_default_theme import _
+
 
 #
 # Associations paragraph default renderer
@@ -45,15 +42,27 @@
     """Associations paragraph default renderer"""
 
     label = _("Default associations renderer")
-    associations = ()
+    i18n_context_attrs = ('title',)
+
+    links = None
+    attachments = None
 
-    i18n_context_attrs = ('title', )
+    def get_associations(self):
+        yield from IAssociationContainer(self.context).get_visible_items(self.request)
+
+    @staticmethod
+    def get_link_info(link):
+        return IAssociationInfo(link)
 
     def update(self):
-        super(AssociationParagraphDefaultRenderer, self).update()
-        self.associations = [{'url': item.get_url(self.request),
-                              'title': IAssociationInfo(item).user_title}
-                             for item in IAssociationContainer(self.context).get_visible_items(self.request)]
+        super().update()
+        self.attachments = []
+        self.links = []
+        for item in self.get_associations():
+            if IExtFile.providedBy(item):
+                self.attachments.append(item)
+            elif IBaseLink.providedBy(item):
+                self.links.append(item)
 
 
 #
@@ -86,8 +95,9 @@
     """Associations container remote content renderer"""
 
     label = _("Include remote content")
+    weight = 10
 
-    i18n_context_attrs = ('title', )
+    i18n_context_attrs = ('title',)
     links = ()
 
     settings_interface = IAssociationParagraphRemoteContentRendererSettings
--- a/src/pyams_default_theme/component/association/templates/association-default.pt	Thu Oct 11 14:51:45 2018 +0200
+++ b/src/pyams_default_theme/component/association/templates/association-default.pt	Fri Oct 12 10:28:46 2018 +0200
@@ -1,9 +1,2 @@
-<i18n:var domain="pyams_default_theme">
-	<h3 tal:content="view.title">§ title</h3>
-	<ul class="inside">
-		<li tal:repeat="item view.associations">
-			<a tal:attributes="href item['url']"
-			   tal:content="item['title']" target="_blank">Link</a>
-		</li>
-	</ul>
-</i18n:var>
+<h3 tal:content="view.title">§ title</h3>
+${structure:provider:pyams.associations}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/component/association/templates/association-viewlet.pt	Fri Oct 12 10:28:46 2018 +0200
@@ -0,0 +1,34 @@
+<ul class="associations">
+	<li tal:repeat="link view.links">
+		<tal:var define="link_info view.get_link_info(link);
+						 description i18n:link.description;">
+			<p>
+				<tal:if condition="description">
+					${structure:tales:html(description)}
+					<br />
+				</tal:if
+				<a tal:define="href link.get_url(request);
+							   target None if href.startswith(request.application_url) else '_blank'"
+				   href="${href}" target="${target}">
+					${link_info.user_title}
+				</a>
+			</p>
+		</tal:var>
+	</li>
+	<li tal:repeat="item view.attachments">
+		<tal:var define="item_info view.get_link_info(item);
+						 description i18n:item.description;
+						 data i18n:item.data">
+			<p>
+				<tal:if condition="description">
+					${structure:tales:html(description)}
+					<br />
+				</tal:if>
+				<a tal:define="href_data tales:absolute_url(data);"
+				   href="${href_data}" target="_blank">
+					${item_info.user_title}
+				</a>
+			</p>
+		</tal:var>
+	</li>
+</ul>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/component/association/viewlet.py	Fri Oct 12 10:28:46 2018 +0200
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+from zope.interface import Interface
+
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationInfo
+from pyams_content.component.extfile.interfaces import IExtFile
+from pyams_content.component.links.interfaces import IBaseLink
+from pyams_template.template import template_config
+from pyams_viewlet.viewlet import ViewContentProvider, contentprovider_config
+
+
+@contentprovider_config(name='pyams.associations', layer=IPyAMSUserLayer, view=Interface)
+@template_config(template='templates/association-viewlet.pt', layer=IPyAMSUserLayer)
+class AssociationContentProvider(ViewContentProvider):
+    """Association default content provider"""
+
+    links = None
+    attachments = None
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.attachments = []
+        self.links = []
+
+    def get_associations(self):
+        yield from IAssociationContainer(self.context).get_visible_items(self.request)
+
+    @staticmethod
+    def get_link_info(link):
+        return IAssociationInfo(link)
+
+    def update(self):
+        super().update()
+        for item in self.get_associations():
+            if IExtFile.providedBy(item):
+                self.attachments.append(item)
+            elif IBaseLink.providedBy(item):
+                self.links.append(item)
--- a/src/pyams_default_theme/component/paragraph/templates/html-default.pt	Thu Oct 11 14:51:45 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/html-default.pt	Fri Oct 12 10:28:46 2018 +0200
@@ -6,4 +6,6 @@
 	<tal:var case="'before-body'">${structure:view.render_illustration()}</tal:var>
 	<div>${structure:tales:html(view.body, 'oid_to_href')}</div>
 	<tal:var case="'after-body'">${structure:view.render_illustration()}</tal:var>
+	<div class="clearfix"></div>
+	${structure:provider:pyams.associations}
 </tal:var>