Added Keynumbers Portlet dev-dc
authorDamien Correia
Fri, 15 Jun 2018 17:42:23 +0200
branchdev-dc
changeset 702 5d1e4e777dbc
parent 693 26d51b558325
child 705 6490cb72a126
child 717 634e5e520bd0
Added Keynumbers Portlet
src/pyams_content/component/keynumber/portlet/__init__.py
src/pyams_content/component/keynumber/portlet/interfaces/__init__.py
src/pyams_content/component/keynumber/portlet/zmi/__init__.py
src/pyams_content/component/keynumber/portlet/zmi/templates/preview.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/keynumber/portlet/__init__.py	Fri Jun 15 17:42:23 2018 +0200
@@ -0,0 +1,54 @@
+#
+# 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'
+
+# import standard library
+
+# import interfaces
+from pyams_content.component.keynumber import IKeyNumberContainerTarget, IKeyNumberContainer
+from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
+from pyams_utils.interfaces import VIEW_PERMISSION
+
+# import packages
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+from pyams_portal.portlet import PortletSettings, portlet_config, Portlet
+
+from pyams_content import _
+
+KEYNUMBER_PORTLET_NAME = "pyams_portal.portlet.keynumber"
+
+
+@implementer(IKeyNumberPortletSettings, IKeyNumberContainerTarget)
+class KeyNumberPortletSettings(PortletSettings):
+    """Key Number portlet settings"""
+
+    title = FieldProperty(IKeyNumberPortletSettings['title'])
+    teaser = FieldProperty(IKeyNumberPortletSettings['teaser'])
+
+    @property
+    def keynumbers(self):
+        return IKeyNumberContainer(self)
+
+
+@portlet_config(permission=VIEW_PERMISSION)
+class KeyNumberPortlet(Portlet):
+    """Key number portlet"""
+
+    name = KEYNUMBER_PORTLET_NAME
+    label = _("Key Numbers")
+
+    toolbar_image = None
+    toolbar_css_class = 'fa fa-fw fa-2x fa-dashboard'
+
+    settings_factory = KeyNumberPortletSettings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/keynumber/portlet/interfaces/__init__.py	Fri Jun 15 17:42:23 2018 +0200
@@ -0,0 +1,34 @@
+#
+# 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 zope.schema import Text, TextLine
+from pyams_content import _
+
+
+class IKeyNumberPortletSettings(IPortletSettings):
+    """Key numbers portlet settings interface"""
+
+    title = TextLine(title=_("Title"),
+                     required=False)
+
+    teaser = Text(title=_("Teaser"),
+                  required=False)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/keynumber/portlet/zmi/__init__.py	Fri Jun 15 17:42:23 2018 +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 zope.interface import Interface
+from pyams_portal.interfaces import IPortletPreviewer
+from pyams_form.interfaces.form import IInnerSubForm, IInnerTabForm
+from pyams_pagelet.interfaces import IPagelet
+from pyams_skin.layer import IPyAMSLayer
+from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+
+# import packages
+from pyams_content.component.keynumber.zmi import KeyNumbersView
+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, PortletSettingsPropertiesEditor
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+
+from pyams_content import _
+
+
+@adapter_config(context=(Interface, IPyAMSLayer, Interface, IKeyNumberPortletSettings), provides=IPortletPreviewer)
+@template_config(template='templates/preview.pt', layer=IPyAMSLayer)
+class KeyNumberPortletPreview(PortletPreviewer):
+    """Key number portlet previewer"""
+
+
+@pagelet_config(name='properties.html', context=IKeyNumberPortletSettings, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class KeyNumberPortletEditor(PortletSettingsEditor):
+    """Key number portlet settings editor"""
+
+    settings = IKeyNumberPortletSettings
+
+
+@adapter_config(name='properties', context=(Interface, IPyAMSLayer, KeyNumberPortletEditor), provides=IInnerTabForm)
+class KeyNumberPortletSettingsPropertiesEditor(PortletSettingsPropertiesEditor):
+    """Key number portlet settings properties editor"""
+
+    def updateWidgets(self, prefix=None):
+        super().updateWidgets(prefix)
+        if 'teaser' in self.widgets:
+            self.widgets['teaser'].widget_css_class = 'textarea'
+
+
+@adapter_config(name='properties.json', context=(IKeyNumberPortletSettings, IPyAMSLayer), provides=IPagelet)
+class KeyNumberPortletAJAXEditor(AJAXEditForm, KeyNumberPortletEditor):
+    """Key number portlet settings editor, JSON renderer"""
+
+
+@adapter_config(name='portlet-keynumbers',
+                context=(IKeyNumberPortletSettings, IPyAMSLayer, PortletSettingsPropertiesEditor),
+                provides=IInnerSubForm)
+class PortletKeynumberLinksView(KeyNumbersView):
+    """Portlet key numbers view"""
+
+    title = _("Key numbers")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/keynumber/portlet/zmi/templates/preview.pt	Fri Jun 15 17:42:23 2018 +0200
@@ -0,0 +1,20 @@
+<div tal:define="settings view.settings" i18n:domain="pyams_content">
+    <strong tal:define="title i18n:settings.title"
+            tal:condition="title"
+            tal:content="title + ' : '">Title</strong>
+    <span tal:content="settings.teaser"></span>
+    <ul>
+	    <li tal:repeat="number settings.keynumbers.get_visible_items()">
+			<span tal:define="label i18n:number.label"
+                  tal:condition="label"
+				  tal:content="label + ' : '">label</span>
+			<span tal:define="number i18n:number.number"
+				  tal:content="number or '--'" class="badge">Number</span>
+			<span tal:define="unit i18n:number.unit"
+				  tal:content="unit or '......'">Unit</span>
+			<span tal:define="txt i18n:number.text"
+				  tal:content="txt">text</span>
+		</li>
+	</ul>
+</div>
+