Don't use standard form and widgets prefix in code
authorThierry Florac <thierry.florac@onf.fr>
Wed, 11 Apr 2018 11:35:07 +0200
changeset 75 02d9ff8d1803
parent 74 46260820b73f
child 76 3d097899a717
Don't use standard form and widgets prefix in code
src/pyams_portal/zmi/layout.py
--- a/src/pyams_portal/zmi/layout.py	Wed Apr 11 11:34:15 2018 +0200
+++ b/src/pyams_portal/zmi/layout.py	Wed Apr 11 11:35:07 2018 +0200
@@ -228,7 +228,8 @@
 
     def updateWidgets(self, prefix=None):
         super(PortalTemplateSlotAddForm, self).updateWidgets()
-        self.widgets['row_id'].value = self.request.params.get('form.widgets.row_id')
+        self.widgets['row_id'].value = self.request.params.get(
+            '{0}{1}row_id'.format(self.prefix, self.widgets.prefix))
         if self.widgets['row_id'].value:
             self.widgets['row_id'].mode = HIDDEN_MODE
 
@@ -253,10 +254,14 @@
     """Portal template slot add form, AJAX handler"""
 
     def get_ajax_output(self, changes):
-        return {'status': 'callback',
-                'callback': 'PyAMS_portal.template.addSlotCallback',
-                'options': {'row_id': changes[0],
-                            'slot_name': changes[1]}}
+        return {
+            'status': 'callback',
+            'callback': 'PyAMS_portal.template.addSlotCallback',
+            'options': {
+                'row_id': changes[0],
+                'slot_name': changes[1]
+            }
+        }
 
 
 @view_config(name='set-template-slot-order.json', context=IPortalTemplate, request_type=IPyAMSLayer,
@@ -295,6 +300,8 @@
 class PortalTemplateSlotPropertiesEditForm(AdminDialogEditForm):
     """Slot properties edit form"""
 
+    prefix = 'slot_properties.'
+
     @property
     def title(self):
         translate = self.request.localizer.translate
@@ -315,7 +322,7 @@
         self.config = IPortalTemplateConfiguration(context)
 
     def getContent(self):
-        slot_name = self.request.params.get('form.widgets.slot_name')
+        slot_name = self.request.params.get('{0}{1}slot_name'.format(self.prefix, self.widgets.prefix))
         return self.config.slot_config[slot_name]
 
     def updateWidgets(self, prefix=None):
@@ -332,10 +339,14 @@
         if changes:
             slot_name = self.widgets['slot_name'].value
             slot_config = self.config.slot_config[slot_name]
-            return {'status': 'success',
-                    'callback': 'PyAMS_portal.template.editSlotCallback',
-                    'options': {'slot_name': slot_name,
-                                'width': slot_config.get_width()}}
+            return {
+                'status': 'success',
+                'callback': 'PyAMS_portal.template.editSlotCallback',
+                'options': {
+                    'slot_name': slot_name,
+                    'width': slot_config.get_width()
+                }
+            }
         else:
             return super(PortalTemplateSlotPropertiesAJAXEditForm, self).get_ajax_output(changes)
 
@@ -408,9 +419,11 @@
         if previewer is not None:
             previewer.update()
             changes['preview'] = previewer.render()
-        return {'status': 'callback',
-                'callback': 'PyAMS_portal.template.addPortletCallback',
-                'options': changes}
+        return {
+            'status': 'callback',
+            'callback': 'PyAMS_portal.template.addPortletCallback',
+            'options': changes
+        }
 
 
 @view_config(name='drag-template-portlet.json', context=IPortalTemplate, request_type=IPyAMSLayer,
@@ -428,10 +441,12 @@
     if previewer is not None:
         previewer.update()
         changes['preview'] = previewer.render()
-    return {'status': 'callback',
-            'close_form': False,
-            'callback': 'PyAMS_portal.template.addPortletCallback',
-            'options': changes}
+    return {
+        'status': 'callback',
+        'close_form': False,
+        'callback': 'PyAMS_portal.template.addPortletCallback',
+        'options': changes
+    }
 
 
 @view_config(name='set-template-portlet-order.json', context=IPortalTemplate, request_type=IPyAMSLayer,
@@ -450,12 +465,14 @@
 class PortalTemplatePortletEditForm(AdminDialogEditForm):
     """Portal template portlet edit form"""
 
+    prefix = 'portlet_properties.'
+
     dialog_class = 'modal-large'
 
     def __call__(self):
         request = self.request
         request.registry.notify(PageletCreatedEvent(self))
-        portlet_id = int(request.params.get('form.widgets.portlet_id'))
+        portlet_id = int(request.params.get('{0}widgets.portlet_id'.format(self.prefix)))
         portlet_config = IPortalPortletsConfiguration(self.context).get_portlet_configuration(portlet_id)
         if portlet_config is None:
             raise NotFound()
@@ -478,13 +495,13 @@
         request = self.request
         request.registry.notify(PageletCreatedEvent(self))
         # load portlet config
-        portlet_id = int(request.params.get('form.widgets.portlet_id'))
+        portlet_id = int(request.params.get('{0}widgets.portlet_id'.format(self.prefix)))
         portlet_config = IPortalPortletsConfiguration(self.context).get_portlet_configuration(portlet_id)
         if portlet_config is None:
             raise NotFound()
         # check inheritance
         old_override = portlet_config.inherit_parent
-        new_override = request.params.get('form.widgets.override_parent')
+        new_override = request.params.get('{0}widgets.override_parent'.format(self.prefix))
         if new_override:
             portlet_config.inherit_parent = False
         else:
@@ -504,12 +521,16 @@
                                                            IPortletPreviewer)
             if previewer is not None:
                 previewer.update()
-                changes.update({'status': 'success',
-                                'message': translate(self.successMessage),
-                                'callback': 'PyAMS_portal.template.editPortletCallback',
-                                'options': {'portlet_id': portlet_id,
-                                            'inherit_parent': portlet_config.inherit_parent,
-                                            'preview': previewer.render()}})
+                changes.update({
+                    'status': 'success',
+                    'message': translate(self.successMessage),
+                    'callback': 'PyAMS_portal.template.editPortletCallback',
+                    'options': {
+                        'portlet_id': portlet_id,
+                        'inherit_parent': portlet_config.inherit_parent,
+                        'preview': previewer.render()
+                    }
+                })
         return changes