# HG changeset patch # User Thierry Florac # Date 1539332926 -7200 # Node ID 97e8610cbabd13f76f447044d1d9bd5376b1d7b3 # Parent 610811d72a1006b50684edd47cd9bd7300b223ee# Parent e5d91569642f8840eadb21f3d8e825bc37f3a921 Merge branch dev-dc diff -r 610811d72a10 -r 97e8610cbabd src/pyams_default_theme/component/association/__init__.py --- 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 diff -r 610811d72a10 -r 97e8610cbabd src/pyams_default_theme/component/association/templates/association-default.pt --- 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 @@ - -

§ title

- -
+

§ title

+${structure:provider:pyams.associations} diff -r 610811d72a10 -r 97e8610cbabd src/pyams_default_theme/component/association/templates/association-viewlet.pt --- /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 @@ + diff -r 610811d72a10 -r 97e8610cbabd src/pyams_default_theme/component/association/viewlet.py --- /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 +# 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) diff -r 610811d72a10 -r 97e8610cbabd src/pyams_default_theme/component/paragraph/templates/html-default.pt --- 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 @@ ${structure:view.render_illustration()}
${structure:tales:html(view.body, 'oid_to_href')}
${structure:view.render_illustration()} +
+ ${structure:provider:pyams.associations}