Added help and permission checker for languages update form
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Oct 2017 09:07:04 +0200
changeset 39 07dc3a8e34f7
parent 38 cd56db960a5d
child 40 687335b57922
Added help and permission checker for languages update form
src/pyams_i18n/zmi/language.py
--- a/src/pyams_i18n/zmi/language.py	Fri Oct 13 09:06:29 2017 +0200
+++ b/src/pyams_i18n/zmi/language.py	Fri Oct 13 09:07:04 2017 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_form.interfaces.form import IWidgetForm
+from pyams_form.interfaces.form import IWidgetForm, IFormHelp, IFormContextPermissionChecker
 from pyams_i18n.interfaces import II18nManager
 from pyams_skin.interfaces import IInnerPage
 from pyams_skin.layer import IPyAMSLayer
@@ -26,8 +26,10 @@
 
 # import packages
 from pyams_form.form import AJAXEditForm
+from pyams_form.help import FormHelp
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.viewlet.menu import MenuItem
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminEditForm
 from pyramid.view import view_config
@@ -61,10 +63,28 @@
 
     fields = field.Fields(II18nManager)
     ajax_handler = 'languages.json'
-    edit_permission = MANAGE_PERMISSION
+    edit_permission = None
 
 
 @view_config(name='languages.json', context=II18nManager, request_type=IPyAMSLayer,
-             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
+             permission=VIEW_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class I18nManagerLanguagesAJAXEditForm(AJAXEditForm, I18nManagerLanguagesEditForm):
     """I18n manager languages edit form, JSON renderer"""
+
+
+@adapter_config(context=(II18nManager, IPyAMSLayer, I18nManagerLanguagesEditForm), provides=IFormHelp)
+class I18nManagerLanguageEditFormHelp(FormHelp):
+    """I18n manager language edit form help adapter"""
+
+    outer_margin = 10
+    message = _("For each selected language, a tab will be associated to each form input to enter matching "
+                "translation.")
+    message_format = 'rest'
+
+
+@adapter_config(context=(II18nManager, IPyAMSLayer, I18nManagerLanguagesEditForm),
+                provides=IFormContextPermissionChecker)
+class I18nManagerLanguageEditFormPermissionChecker(ContextRequestViewAdapter):
+    """I18n manager language edit form permission checker"""
+
+    edit_permission = MANAGE_PERMISSION