Added base of view content portlet
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 11:58:14 +0200
changeset 116 f356c84860a3
parent 115 67a6a3b92612
child 117 2cbfaf8aa759
Added base of view content portlet
src/pyams_content/shared/view/portlet/__init__.py
src/pyams_content/shared/view/portlet/interfaces.py
src/pyams_content/shared/view/portlet/templates/view-items-list.pt
src/pyams_content/shared/view/portlet/templates/view-with-images-list.pt
src/pyams_content/shared/view/portlet/zmi/__init__.py
src/pyams_content/shared/view/portlet/zmi/templates/view-items-list-preview.pt
--- /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 <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'
+
+
+# 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")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/view/portlet/interfaces.py	Wed Jul 12 11:58:14 2017 +0200
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 2008-2015 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'
+
+
+# import standard library
+
+# import interfaces
+from pyams_portal.interfaces import IPortletSettings
+
+# import packages
+from pyams_sequence.schema import InternalReference
+
+from pyams_content import _
+
+
+class IViewItemsPortletSettings(IPortletSettings):
+    """View items portlet settings interface"""
+
+    view = InternalReference(title=_("Selected view"),
+                             description=_("Reference to the view from which items are extracted"),
+                             required=True)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/view/portlet/templates/view-items-list.pt	Wed Jul 12 11:58:14 2017 +0200
@@ -0,0 +1,3 @@
+<div tal:repeat="item view.settings.get_items(context)">
+	<tal:var content="i18n:item.title" />
+</div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/view/portlet/zmi/__init__.py	Wed Jul 12 11:58:14 2017 +0200
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2008-2015 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'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.shared.view.portlet.interfaces import IViewItemsPortletSettings
+from pyams_pagelet.interfaces import IPagelet
+from pyams_portal.interfaces import IPortletPreviewer
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+
+# import packages
+from pyams_form.form import AJAXEditForm
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_portal.portlet import PortletPreviewer
+from pyams_portal.zmi.portlet import PortletSettingsEditor
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+from zope.interface import Interface
+
+
+@pagelet_config(name='properties.html', context=IViewItemsPortletSettings, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class ViewItemsPortletSettingsEditor(PortletSettingsEditor):
+    """View items portlet settings editor"""
+
+    settings = IViewItemsPortletSettings
+
+
+@adapter_config(name='properties.json', context=(IViewItemsPortletSettings, IPyAMSLayer), provides=IPagelet)
+class ViewItemsPortletSettingsAJAXEditor(AJAXEditForm, ViewItemsPortletSettingsEditor):
+    """View items portlet settings editor, JSON renderer"""
+
+
+@adapter_config(context=(Interface, IPyAMSLayer, Interface, IViewItemsPortletSettings), provides=IPortletPreviewer)
+@template_config(template='templates/view-items-list-preview.pt', layer=IPyAMSLayer)
+class ViewItemsPortletPreviewer(PortletPreviewer):
+    """Image portlet previewer"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/view/portlet/zmi/templates/view-items-list-preview.pt	Wed Jul 12 11:58:14 2017 +0200
@@ -0,0 +1,22 @@
+<tal:var define="settings view.settings">
+	<tal:if condition="settings.visible">
+		<tal:var define="items settings.get_items(context)">
+			<tal:if condition="items">
+				<div tal:repeat="item items">
+					<tal:var content="i18n:item.title" />
+				</div>
+			</tal:if>
+			<tal:if condition="not:items" i18n:translate="">
+				No result found
+			</tal:if>
+		</tal:var>
+	</tal:if>
+	<tal:if condition="not settings.visible">
+		<div class="text-center padding-y-5">
+			<span class="fa-stack fa-lg">
+				<i class="fa fa-eye fa-stack-1x"></i>
+				<i class="fa fa-ban fa-stack-2x text-danger"></i>
+			</span>
+		</div>
+	</tal:if>
+</tal:var>