Updated interfaces to handle presentation templates on shared tools and contents
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Jun 2018 17:26:58 +0200
changeset 622 76b7c0b5bfa6
parent 621 a75b1fc09fde
child 623 1978e4dad1d8
Updated interfaces to handle presentation templates on shared tools and contents
src/pyams_content/shared/common/interfaces/__init__.py
src/pyams_content/shared/common/interfaces/types.py
src/pyams_content/shared/common/portal.py
src/pyams_content/shared/common/zmi/portal.py
src/pyams_content/shared/form/interfaces/__init__.py
src/pyams_content/shared/form/manager.py
src/pyams_content/shared/news/interfaces/__init__.py
src/pyams_content/shared/news/manager.py
--- a/src/pyams_content/shared/common/interfaces/__init__.py	Mon Jun 11 16:48:57 2018 +0200
+++ b/src/pyams_content/shared/common/interfaces/__init__.py	Mon Jun 11 17:26:58 2018 +0200
@@ -102,6 +102,10 @@
     shared_content_factory = Attribute("Shared data factory")
 
 
+class ISharedToolPortalContext(ISharedTool, IPortalContext):
+    """Shared tool with portal context"""
+
+
 class ISharedToolRoles(IBaseContentManagerRoles):
     """Shared tool roles"""
 
--- a/src/pyams_content/shared/common/interfaces/types.py	Mon Jun 11 16:48:57 2018 +0200
+++ b/src/pyams_content/shared/common/interfaces/types.py	Mon Jun 11 17:26:58 2018 +0200
@@ -17,6 +17,7 @@
 
 # import interfaces
 from pyams_content.shared.common.interfaces import ISharedTool
+from pyams_portal.interfaces import IPortalContext
 from zope.container.interfaces import IContainer
 from zope.location.interfaces import ILocation
 
@@ -100,3 +101,7 @@
     """Shared tool containing typed data"""
 
     shared_content_types_fields = Attribute("Content fields interface")
+
+
+class ITypedSharedToolPortalContext(ITypedSharedTool, IPortalContext):
+    """Typed shared tool with portal context"""
--- a/src/pyams_content/shared/common/portal.py	Mon Jun 11 16:48:57 2018 +0200
+++ b/src/pyams_content/shared/common/portal.py	Mon Jun 11 17:26:58 2018 +0200
@@ -16,11 +16,12 @@
 # import standard library
 
 # import interfaces
-from pyams_content.shared.common.interfaces import IBaseSharedTool
-from pyams_portal.interfaces import IPortalPage
+from pyams_content.shared.common.interfaces import IBaseSharedTool, IWfSharedContentPortalContext
+from pyams_portal.interfaces import IPortalPage, PORTAL_PAGE_KEY
 
 # import packages
 from pyams_portal.page import PortalPage
+from pyams_utils.adapter import adapter_config, get_annotation_adapter
 from pyams_utils.traversing import get_parent
 
 
@@ -34,3 +35,9 @@
     @property
     def parent(self):
         return get_parent(self, IBaseSharedTool, allow_context=False)
+
+
+@adapter_config(context=IWfSharedContentPortalContext, provides=IPortalPage)
+def shared_content_portal_page_adapter(context):
+    """Shared content portal page adapter"""
+    return get_annotation_adapter(context, PORTAL_PAGE_KEY, SharedContentPortalPage)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/zmi/portal.py	Mon Jun 11 17:26:58 2018 +0200
@@ -0,0 +1,72 @@
+#
+# 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.shared.common import IWfSharedContent
+from pyams_content.shared.common.interfaces import IWfSharedContentPortalContext, ISharedToolPortalContext, ISharedTool
+from pyams_content.shared.common.interfaces.types import ITypedSharedToolPortalContext
+from pyams_form.interfaces.form import IFormHelp
+from pyams_skin.layer import IPyAMSLayer
+from pyams_zmi.layer import IAdminLayer
+
+# import packages
+from pyams_form.form import ajax_config
+from pyams_form.help import FormHelp
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_portal import MANAGE_TEMPLATE_PERMISSION
+from pyams_portal.zmi.page import PortalContextTemplatePropertiesEditForm
+from pyams_utils.adapter import adapter_config
+
+from pyams_content import _
+
+
+@pagelet_config(name='template-properties.html', context=ISharedToolPortalContext, layer=IPyAMSLayer,
+                permission=MANAGE_TEMPLATE_PERMISSION)
+@pagelet_config(name='template-properties.html', context=ITypedSharedToolPortalContext, layer=IPyAMSLayer,
+                permission=MANAGE_TEMPLATE_PERMISSION)
+@ajax_config(name='template-properties.json', context=ISharedToolPortalContext, layer=IPyAMSLayer)
+@ajax_config(name='template-properties.json', context=ITypedSharedToolPortalContext, layer=IPyAMSLayer)
+class SharedToolTemplatePropertiesEditForm(PortalContextTemplatePropertiesEditForm):
+    """Shared content template properties edit form"""
+
+    legend = _("Edit default template properties")
+
+
+@adapter_config(context=(ISharedToolPortalContext, IAdminLayer, SharedToolTemplatePropertiesEditForm),
+                provides=IFormHelp)
+@adapter_config(context=(ITypedSharedToolPortalContext, IAdminLayer, SharedToolTemplatePropertiesEditForm),
+                provides=IFormHelp)
+class SharedToolPortalContextPropertiesEditFormHelpAdapter(FormHelp):
+    """Shared tool template properties edit form help adapter"""
+
+    message = _("**This form allows you to select shared content default template.**\n"
+                "\n"
+                "If you choose to use a shared template, you can only adjust settings of "
+                "each portlet individually but can't change portlets list or page configuration.\n"
+                "\n"
+                "If you use a local template, you can define a whole custom "
+                "configuration but the template definition can't be reused anywhere...""")
+    message_format = 'rest'
+
+
+@pagelet_config(name='template-properties.html', context=IWfSharedContentPortalContext, layer=IPyAMSLayer,
+                permission=MANAGE_TEMPLATE_PERMISSION)
+@ajax_config(name='template-properties.json', context=IWfSharedContent, layer=IPyAMSLayer)
+class SharedContentTemplatePropertiesEditForm(PortalContextTemplatePropertiesEditForm):
+    """Shared content template properties edit form"""
+
+    override_legend = _("Override tool default template")
--- a/src/pyams_content/shared/form/interfaces/__init__.py	Mon Jun 11 16:48:57 2018 +0200
+++ b/src/pyams_content/shared/form/interfaces/__init__.py	Mon Jun 11 17:26:58 2018 +0200
@@ -16,7 +16,8 @@
 # import standard library
 
 # import interfaces
-from pyams_content.shared.common.interfaces import ISharedTool, ISharedContent, IWfSharedContentPortalContext
+from pyams_content.shared.common.interfaces import ISharedContent, IWfSharedContentPortalContext, \
+    ISharedToolPortalContext
 from zope.annotation.interfaces import IAttributeAnnotatable
 from zope.container.interfaces import IContainer, IContained
 
@@ -36,7 +37,7 @@
 FORM_FIELD_CONTAINER_KEY = 'pyams_content.shared.form_fields'
 
 
-class IFormsManager(ISharedTool):
+class IFormsManager(ISharedToolPortalContext):
     """Forms manager interface"""
 
 
--- a/src/pyams_content/shared/form/manager.py	Mon Jun 11 16:48:57 2018 +0200
+++ b/src/pyams_content/shared/form/manager.py	Mon Jun 11 17:26:58 2018 +0200
@@ -32,7 +32,7 @@
 from zope.interface import implementer
 
 
-@implementer(IFormsManager, IPortalContext)
+@implementer(IFormsManager)
 class FormsManager(SharedTool):
     """Forms manager class"""
 
--- a/src/pyams_content/shared/news/interfaces/__init__.py	Mon Jun 11 16:48:57 2018 +0200
+++ b/src/pyams_content/shared/news/interfaces/__init__.py	Mon Jun 11 17:26:58 2018 +0200
@@ -16,8 +16,8 @@
 # import standard library
 
 # import interfaces
-from pyams_content.shared.common.interfaces import ISharedTool, ISharedContent, \
-    IWfSharedContentPortalContext
+from pyams_content.shared.common.interfaces import ISharedContent, \
+    IWfSharedContentPortalContext, ISharedToolPortalContext
 
 # import packages
 from zope.interface import Interface
@@ -29,7 +29,7 @@
 NEWS_CONTENT_NAME = _("News topic")
 
 
-class INewsManager(ISharedTool):
+class INewsManager(ISharedToolPortalContext):
     """News manager interface"""
 
 
--- a/src/pyams_content/shared/news/manager.py	Mon Jun 11 16:48:57 2018 +0200
+++ b/src/pyams_content/shared/news/manager.py	Mon Jun 11 17:26:58 2018 +0200
@@ -21,7 +21,6 @@
 from pyams_content.reference.pictograms.interfaces import IPictogramManagerTarget
 from pyams_content.shared.common.interfaces import ISharedContentFactory
 from pyams_content.shared.news.interfaces import INewsManager, NEWS_CONTENT_TYPE, INewsManagerFactory
-from pyams_portal.interfaces import IPortalContext
 from zope.component.interfaces import ISite
 from zope.lifecycleevent.interfaces import IObjectAddedEvent
 
@@ -36,8 +35,7 @@
 from zope.schema.fieldproperty import FieldProperty
 
 
-@implementer(INewsManager, IParagraphFactorySettings, IThemesManagerTarget, IPictogramManagerTarget,
-             IPortalContext)
+@implementer(INewsManager, IParagraphFactorySettings, IThemesManagerTarget, IPictogramManagerTarget)
 class NewsManager(SharedTool):
     """News manager class"""