Created Association content provider;
Updated Association default renderer and template;
--- a/src/pyams_default_theme/component/association/__init__.py Tue Oct 09 16:37:24 2018 +0200
+++ b/src/pyams_default_theme/component/association/__init__.py Tue Oct 09 16:40:40 2018 +0200
@@ -24,7 +24,8 @@
# import interfaces
from pyams_content.component.association.interfaces import IAssociationParagraph, IAssociationInfo, \
IAssociationContainer
-from pyams_content.component.links.interfaces import IInternalLink
+from pyams_content.component.extfile import IExtFile
+from pyams_content.component.links.interfaces import IInternalLink, IBaseLink
from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer
from pyams_content.features.renderer.interfaces import IContentRenderer
from pyams_content.features.renderer.skin import BaseContentRenderer
@@ -45,16 +46,30 @@
"""Associations paragraph default renderer"""
label = _("Default associations renderer")
- associations = ()
+ i18n_context_attrs = ('title', )
+
+ links = None
+ attachments = None
- i18n_context_attrs = ('title', )
+ 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(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()
+ for item in self.get_associations():
+ if IExtFile.providedBy(item):
+ self.attachments.append(item)
+ elif IBaseLink.providedBy(item):
+ self.links.append(item)
#
# Associations paragraph remote content renderer
--- a/src/pyams_default_theme/component/association/templates/association-default.pt Tue Oct 09 16:37:24 2018 +0200
+++ b/src/pyams_default_theme/component/association/templates/association-default.pt Tue Oct 09 16:40:40 2018 +0200
@@ -1,9 +1,4 @@
<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>
+ ${structure:provider:pyams.association}
</i18n:var>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/component/association/templates/association-viewlet.pt Tue Oct 09 16:40:40 2018 +0200
@@ -0,0 +1,22 @@
+<ul>
+ <li tal:repeat="link view.links">
+ <tal:var tal:define="link_info view.get_link_info(link);
+ description i18n:link.description;">
+ <p>${structure:tales:html(description)}<br tal:condition="description">
+ <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 tal:define="item_info view.get_link_info(item);
+ description i18n:item.description;
+ data i18n:item.data">
+ <p>${structure:tales:html(description)}<br tal:condition="description">
+ <a tal:define="href_data tales:absolute_url(data);"
+ href="${href_data}">${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 Tue Oct 09 16:40:40 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.association', 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)