diff -r 67a6a3b92612 -r f356c84860a3 src/pyams_content/shared/view/portlet/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/shared/view/portlet/__init__.py Wed Jul 12 11:58:14 2017 +0200 @@ -0,0 +1,73 @@ +# +# Copyright (c) 2008-2015 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' + + +# import standard library + +# import interfaces +from pyams_content.shared.view.portlet.interfaces import IViewItemsPortletSettings +from pyams_portal.interfaces import IPortalContext, IPortletRenderer +from pyams_skin.layer import IPyAMSLayer +from pyams_utils.interfaces import PUBLIC_PERMISSION + +# import packages +from pyams_content.workflow import PUBLISHED_STATES +from pyams_portal.portlet import PortletSettings, portlet_config, Portlet, PortletRenderer +from pyams_sequence.utility import get_sequence_target +from pyams_template.template import template_config +from pyams_utils.adapter import adapter_config +from zope.interface import implementer, Interface +from zope.schema.fieldproperty import FieldProperty + +from pyams_content import _ + + +VIEW_PORTLET_NAME = 'pyams_content.portlet.view' + + +@implementer(IViewItemsPortletSettings) +class ViewItemsPortletSettings(PortletSettings): + """View items portlet settings""" + + view = FieldProperty(IViewItemsPortletSettings['view']) + + def get_view(self): + if self.view is not None: + return get_sequence_target(self.view, state=PUBLISHED_STATES) + + def get_items(self, context): + view = self.get_view() + if view is not None: + return view.get_results(context) + + +@portlet_config(permission=PUBLIC_PERMISSION) +class ViewItemsPortlet(Portlet): + """View items portlet""" + + name = VIEW_PORTLET_NAME + label = _("View items") + + toolbar_image = None + toolbar_css_class = 'fa fa-fw fa-2x fa-th-list' + + settings_class = ViewItemsPortletSettings + + +@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, IViewItemsPortletSettings), provides=IPortletRenderer) +@template_config(template='templates/view-items-list.pt', layer=IPyAMSLayer) +class ViewItemsPortletRenderer(PortletRenderer): + """View items portlet renderer""" + + label = _("Simple list view")