Added form help
authorThierry Florac <thierry.florac@onf.fr>
Wed, 20 Jun 2018 14:05:50 +0200
changeset 122 4fcb3a5afa91
parent 121 a7c7efdc532b
child 123 827f7278b9fb
Added form help
src/pyams_portal/zmi/portlet.py
--- a/src/pyams_portal/zmi/portlet.py	Wed Jun 20 14:04:53 2018 +0200
+++ b/src/pyams_portal/zmi/portlet.py	Wed Jun 20 14:05:50 2018 +0200
@@ -9,6 +9,10 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from z3c.form.interfaces import INPUT_MODE
+
+from pyams_form.help import FormHelp
+from pyams_zmi.layer import IAdminLayer
 
 __docformat__ = 'restructuredtext'
 
@@ -16,7 +20,7 @@
 # import standard library
 
 # import interfaces
-from pyams_form.interfaces.form import IInnerTabForm
+from pyams_form.interfaces.form import IInnerTabForm, IFormHelp
 from pyams_portal.interfaces import IPortlet, IPortalTemplate, IPortalPage, MANAGE_TEMPLATE_PERMISSION, \
     IPortletSettings, IPortletRendererSettings
 from pyams_skin.layer import IPyAMSLayer
@@ -64,6 +68,11 @@
     def configuration(self):
         return self.context.configuration
 
+    @reify
+    def portlet(self):
+        registry = self.request.registry
+        return registry.queryUtility(IPortlet, name=self.configuration.portlet_name)
+
     @property
     def override_label(self):
         translate = self.request.localizer.translate
@@ -83,10 +92,19 @@
     def get_ajax_handler(self):
         return absolute_url(self.configuration.__parent__, self.request, self.ajax_handler)
 
-    @reify
-    def portlet(self):
-        registry = self.request.registry
-        return registry.queryUtility(IPortlet, name=self.configuration.portlet_name)
+
+@adapter_config(context=(Interface, IAdminLayer, PortletSettingsEditor), provides=IFormHelp)
+class PortletSettingsEditorFormHelpAdapter(FormHelp):
+    """Portlet settings editor form help adapter"""
+
+    def __new__(cls, context, request, view):
+        configuration = view.configuration
+        if (not configuration.can_inherit) or (view.mode != INPUT_MODE):
+            return None
+        return FormHelp.__new__(cls)
+
+    message = _("""WARNING: Portlet properties are saved automatically when changing inherit mode!!""")
+    message_format = 'rest'
 
 
 @adapter_config(name='properties', context=(Interface, IPyAMSLayer, PortletSettingsEditor), provides=IInnerTabForm)
@@ -102,8 +120,9 @@
 
     @property
     def fields(self):
-        fields = field.Fields(self.parent_form.settings).omit('__name__', 'renderer') + \
-                 field.Fields(self.parent_form.settings).select('renderer')
+        settings = self.parent_form.settings
+        fields = field.Fields(settings).omit('__name__', 'renderer') + \
+                 field.Fields(settings).select('renderer')
         fields['renderer'].widgetFactory = PortletRendererFieldWidget
         return fields