# HG changeset patch # User Damien Correia # Date 1539096040 -7200 # Node ID f805794b2500a9695a354b00f697711a3dfb069e # Parent 5276328160b3021703ccac1c382f1f3127deb5de Created Association content provider; Updated Association default renderer and template; diff -r 5276328160b3 -r f805794b2500 src/pyams_default_theme/component/association/__init__.py --- 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 diff -r 5276328160b3 -r f805794b2500 src/pyams_default_theme/component/association/templates/association-default.pt --- 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 @@

ยง title

- + ${structure:provider:pyams.association}
diff -r 5276328160b3 -r f805794b2500 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 Tue Oct 09 16:40:40 2018 +0200 @@ -0,0 +1,22 @@ + diff -r 5276328160b3 -r f805794b2500 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 Tue Oct 09 16:40:40 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.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)