Added shared content "specificities" management
authorThierry Florac <thierry.florac@onf.fr>
Fri, 28 Dec 2018 10:21:37 +0100
changeset 1197 dc3c42f73b0e
parent 1196 8e8f528f8d3b
child 1198 d8fbefa460d6
Added shared content "specificities" management
src/pyams_content/shared/common/interfaces/specificities.py
src/pyams_content/shared/common/portlet/specificities.py
src/pyams_content/shared/common/portlet/zmi/specificities.py
src/pyams_content/shared/common/portlet/zmi/templates/specificities-preview.pt
src/pyams_content/shared/common/specificities.py
src/pyams_content/shared/common/zmi/specificities.py
src/pyams_content/shared/common/zmi/templates/header.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/interfaces/specificities.py	Fri Dec 28 10:21:37 2018 +0100
@@ -0,0 +1,31 @@
+#
+# 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'
+
+from zope.schema import Choice
+
+from pyams_content.component.paragraph import IBaseParagraph
+
+from pyams_content import _
+
+
+SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_RENDERERS = 'pyams_content.content_specificities.renderers'
+
+
+class ISharedContentSpecificitiesParagraph(IBaseParagraph):
+    """Shared content specificities portlet settings"""
+
+    renderer = Choice(title=_("Specificities renderer"),
+                      description=_("Presentation template used for content specificities"),
+                      vocabulary=SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_RENDERERS,
+                      default='default')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/portlet/specificities.py	Fri Dec 28 10:21:37 2018 +0100
@@ -0,0 +1,44 @@
+#
+# 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'
+
+from pyams_default_theme.shared.common.interfaces import ISharedContentSpecificitiesPortletSettings
+from pyams_portal.portlet import Portlet, PortletSettings, portlet_config
+from pyams_utils.factory import factory_config
+from pyams_utils.interfaces import VIEW_PERMISSION
+
+from pyams_content import _
+
+
+#
+# Shared content specificities portlet
+#
+
+SHARED_CONTENT_SPECIFICITIES_PORTLET_NAME = 'pyams_content.portlet.shared.specificities'
+
+
+@factory_config(provided=ISharedContentSpecificitiesPortletSettings)
+class SharedContentSpecificitiesPortletSettings(PortletSettings):
+    """Shared content specificities portlet settings"""
+
+
+@portlet_config(permission=VIEW_PERMISSION)
+class SharedContentSpecificitiesPortlet(Portlet):
+    """Shared content specificities portlet"""
+
+    name = SHARED_CONTENT_SPECIFICITIES_PORTLET_NAME
+    label = _("Content specificities portlet")
+
+    toolbar_css_class = 'fa fa-fw fa-2x fa-paperclip'
+
+    settings_factory = ISharedContentSpecificitiesPortletSettings
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/portlet/zmi/specificities.py	Fri Dec 28 10:21:37 2018 +0100
@@ -0,0 +1,59 @@
+#
+# 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'
+
+from zope.interface import Interface
+
+from pyams_default_theme.shared.common.interfaces import ISharedContentSpecificitiesPortletSettings
+from pyams_form.form import AJAXEditForm
+from pyams_form.interfaces.form import IInnerTabForm
+from pyams_pagelet.interfaces import IPagelet
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_portal.interfaces import IPortletPreviewer
+from pyams_portal.portlet import PortletPreviewer
+from pyams_portal.zmi.portlet import PortletSettingsEditor, PortletSettingsPropertiesEditor
+from pyams_skin.layer import IPyAMSLayer
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+
+
+#
+# Shared content specificities portlet views
+#
+
+@pagelet_config(name='properties.html', context=ISharedContentSpecificitiesPortletSettings, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class SharedContentSpecificitiesPortletSettingsEditor(PortletSettingsEditor):
+    """Shared content specificities portlet settings editor"""
+
+    settings = ISharedContentSpecificitiesPortletSettings
+
+
+@adapter_config(name='properties', context=(Interface, IPyAMSLayer, SharedContentSpecificitiesPortletSettingsEditor),
+                provides=IInnerTabForm)
+class SharedContentSpecificitiesPortletSettingsPropertiesEditor(PortletSettingsPropertiesEditor):
+    """Shared content specificities portlet settings properties editor"""
+
+
+@adapter_config(name='properties.json', context=(ISharedContentSpecificitiesPortletSettings, IPyAMSLayer),
+                provides=IPagelet)
+class SharedContentSpecificitiesPortletAJAXEditor(AJAXEditForm, SharedContentSpecificitiesPortletSettingsEditor):
+    """Shared content specificities portlet settings editor, JSON renderer"""
+
+
+@adapter_config(context=(Interface, IPyAMSLayer, Interface, ISharedContentSpecificitiesPortletSettings),
+                provides=IPortletPreviewer)
+@template_config(template='templates/specificities-preview.pt', layer=IPyAMSLayer)
+class SharedContentSpecificitiesPortletPreviewer(PortletPreviewer):
+    """Shared content specificities portlet previewer"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/specificities.py	Fri Dec 28 10:21:37 2018 +0100
@@ -0,0 +1,49 @@
+#
+# 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'
+
+from zope.schema.fieldproperty import FieldProperty
+
+from pyams_content.component.paragraph import BaseParagraph
+from pyams_content.features.renderer import RenderersVocabulary
+from pyams_content.shared.common.interfaces.specificities import ISharedContentSpecificitiesParagraph, \
+    SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_RENDERERS
+from pyams_utils.factory import factory_config
+from pyams_utils.vocabulary import vocabulary_config
+
+from pyams_content import _
+
+
+#
+# Shared content specificities paragraph
+#
+
+SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_TYPE = 'ContentSpecificities'
+SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_NAME = _('Content specificities')
+
+
+@factory_config(provided=ISharedContentSpecificitiesParagraph)
+class SharedContentSpecificitiesParagraph(BaseParagraph):
+    """Shared content specificities paragraph"""
+
+    icon_hint = _("Content specificities")
+    icon_class = 'fa-paperclip'
+
+    renderer = FieldProperty(ISharedContentSpecificitiesParagraph['renderer'])
+
+
+@vocabulary_config(name=SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_RENDERERS)
+class SharedContentSpecificitiesParagraphRendererVocabulary(RenderersVocabulary):
+    """Shared content specificities renderers vocabulary"""
+
+    content_interface = ISharedContentSpecificitiesParagraph
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/zmi/specificities.py	Fri Dec 28 10:21:37 2018 +0100
@@ -0,0 +1,123 @@
+#
+# 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'
+
+from z3c.form import button, field
+from z3c.form.interfaces import INPUT_MODE
+from zope.interface import implementer
+
+from pyams_content.component.paragraph import BaseParagraphFactory, IParagraphContainerTarget
+from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphFactory, PARAGRAPH_HIDDEN_FIELDS
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphContainerView, IParagraphInnerEditFormButtons
+from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor
+from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
+from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
+from pyams_content.shared.common.interfaces.specificities import ISharedContentSpecificitiesParagraph
+from pyams_content.shared.common.specificities import SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_NAME, \
+    SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_TYPE, SharedContentSpecificitiesParagraph
+from pyams_form.form import ajax_config
+from pyams_form.interfaces.form import IInnerForm
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import utility_config
+from pyams_viewlet.viewlet import viewlet_config
+from pyams_zmi.form import AdminDialogAddForm
+
+from pyams_content import _
+
+
+#
+# Shared content specificities paragraph views
+#
+
+@utility_config(name=SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_TYPE, provides=IParagraphFactory)
+class SharedContentSpecificitiesParagraphFactory(BaseParagraphFactory):
+    """Shared content specificities paragraph factory"""
+
+    name = SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_NAME
+    content_type = SharedContentSpecificitiesParagraph
+    secondary_menu = True
+
+
+@viewlet_config(name='add-specificities-paragraph.menu', context=IParagraphContainerTarget,
+                view=IParagraphContainerView,
+                layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=600)
+class SharedContentSpecificitiesParagraphAddMenu(BaseParagraphAddMenu):
+    """Shared Content Specificities paragraph add menu"""
+
+    label = _("Content specificities...")
+    label_css_class = 'fa fa-fw ' + SharedContentSpecificitiesParagraph.icon_class
+
+    url = 'add-specificities-paragraph.html'
+    paragraph_type = SHARED_CONTENT_SPECIFICITIES_PARAGRAPH_TYPE
+
+
+@pagelet_config(name='add-specificities-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+                permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='add-specificities-paragraph.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+             base=BaseParagraphAJAXAddForm)
+class SharedContentSpecificitiesParagraphAddForm(AdminDialogAddForm):
+    """Shared Content Specificities paragraph add form"""
+
+    legend = _("Add shared content specificities")
+    dialog_class = 'modal-large'
+    icon_css_class = "fa fa-fw " + SharedContentSpecificitiesParagraph.icon_class
+
+    fields = field.Fields(ISharedContentSpecificitiesParagraph).omit(*PARAGRAPH_HIDDEN_FIELDS)
+    fields['renderer'].widgetFactory = RendererFieldWidget
+
+    edit_permission = MANAGE_CONTENT_PERMISSION
+
+    def create(self, data):
+        return SharedContentSpecificitiesParagraph()
+
+    def add(self, object):
+        IParagraphContainer(self.context).append(object)
+
+
+@pagelet_config(name='properties.html', context=ISharedContentSpecificitiesParagraph, layer=IPyAMSLayer,
+                permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='properties.json', context=ISharedContentSpecificitiesParagraph, request_type=IPyAMSLayer,
+             base=BaseParagraphAJAXEditForm)
+class SharedContentSpecificitiesParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm):
+    """Shared content specificities paragraph properties edit form"""
+
+    prefix = 'specificities_properties.'
+
+    legend = _("Edit specificities properties")
+    icon_css_class = "fa fa-fw " + SharedContentSpecificitiesParagraph.icon_class
+
+    fields = field.Fields(ISharedContentSpecificitiesParagraph).omit(*PARAGRAPH_HIDDEN_FIELDS)
+    fields['renderer'].widgetFactory = RendererFieldWidget
+
+    edit_permission = MANAGE_CONTENT_PERMISSION
+
+
+@adapter_config(context=(ISharedContentSpecificitiesParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
+@ajax_config(name='inner-properties.json', context=SharedContentSpecificitiesParagraph, layer=IPyAMSLayer,
+             base=BaseParagraphAJAXEditForm)
+@implementer(IInnerForm)
+class SharedContentSpecificitiesParagraphInnerEditForm(SharedContentSpecificitiesParagraphPropertiesEditForm):
+    """Shared Content specificities paragraph inner edit form"""
+
+    legend = None
+
+    @property
+    def buttons(self):
+        if self.mode == INPUT_MODE:
+            return button.Buttons(IParagraphInnerEditFormButtons)
+        else:
+            return button.Buttons()
--- a/src/pyams_content/shared/common/zmi/templates/header.pt	Fri Dec 28 10:20:33 2018 +0100
+++ b/src/pyams_content/shared/common/zmi/templates/header.pt	Fri Dec 28 10:21:37 2018 +0100
@@ -10,7 +10,7 @@
 				<i class="fa fa-chevron-left padding-right-10"></i>
 			</a>
 			<tal:if condition="config.display_content_icon">
-				<i tal:attributes="class view.icon_class"></i>
+				<i class="${view.icon_class}"></i>
 			</tal:if>
 			${view.title}
 		</h1>