# HG changeset patch # User Damien Correia # Date 1529077343 -7200 # Node ID 5d1e4e777dbc8a63b83e236d92cd50a120eb9052 # Parent 26d51b5583251c56baf30e761dd8452cb69ab300 Added Keynumbers Portlet diff -r 26d51b558325 -r 5d1e4e777dbc src/pyams_content/component/keynumber/portlet/__init__.py --- /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 +# 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 diff -r 26d51b558325 -r 5d1e4e777dbc src/pyams_content/component/keynumber/portlet/interfaces/__init__.py --- /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 +# 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) + diff -r 26d51b558325 -r 5d1e4e777dbc src/pyams_content/component/keynumber/portlet/zmi/__init__.py --- /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 +# 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") diff -r 26d51b558325 -r 5d1e4e777dbc 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/zmi/templates/preview.pt Fri Jun 15 17:42:23 2018 +0200 @@ -0,0 +1,20 @@ +
+ Title + +
    +
  • + label + Number + Unit + text +
  • +
+
+