Small refactoring in shared contents properties edit forms
authorThierry Florac <tflorac@ulthar.net>
Wed, 04 Sep 2019 15:57:43 +0200
changeset 1342 999fa08d99c2
parent 1341 09247c61f985
child 1343 530cbb970243
Small refactoring in shared contents properties edit forms
src/pyams_content/shared/common/zmi/properties.py
src/pyams_content/shared/common/zmi/types/__init__.py
src/pyams_content/shared/logo/zmi/properties.py
--- a/src/pyams_content/shared/common/zmi/properties.py	Wed Sep 04 15:56:28 2019 +0200
+++ b/src/pyams_content/shared/common/zmi/properties.py	Wed Sep 04 15:57:43 2019 +0200
@@ -77,16 +77,19 @@
 
     legend = _("Content properties")
 
+    interface = IWfSharedContent
+    fieldnames = ('title', 'short_name', 'content_url', 'header', 'description', 'notepad')
+
     @property
     def fields(self):
-        fields = field.Fields(IWfSharedContent).select('title', 'short_name', 'content_url',
-                                                       'header', 'description', 'notepad')
-        fields['title'].widgetFactory = I18nSEOTextLineFieldWidget
-        if not self.context.handle_content_url:
+        fields = field.Fields(self.interface).select(*self.fieldnames)
+        if 'title' in fields:
+            fields['title'].widgetFactory = I18nSEOTextLineFieldWidget
+        if ('content_url' in fields) and not self.context.handle_content_url:
             fields = fields.omit('content_url')
-        if not self.context.handle_header:
+        if ('header' in fields) and not self.context.handle_header:
             fields = fields.omit('header')
-        if not self.context.handle_description:
+        if ('description' in fields) and not self.context.handle_description:
             fields = fields.omit('description')
         return fields
 
--- a/src/pyams_content/shared/common/zmi/types/__init__.py	Wed Sep 04 15:56:28 2019 +0200
+++ b/src/pyams_content/shared/common/zmi/types/__init__.py	Wed Sep 04 15:57:43 2019 +0200
@@ -404,19 +404,8 @@
     """Typed shared content properties edit form"""
 
     interface = IWfTypedSharedContent
-
-    @property
-    def fields(self):
-        fields = field.Fields(self.interface).select('title', 'short_name', 'content_url',
-                                                     'data_type', 'header', 'description', 'notepad')
-        fields['title'].widgetFactory = I18nSEOTextLineFieldWidget
-        if not self.context.handle_content_url:
-            fields = fields.omit('content_url')
-        if not self.context.handle_header:
-            fields = fields.omit('header')
-        if not self.context.handle_description:
-            fields = fields.omit('description')
-        return fields
+    fieldnames = ('title', 'short_name', 'content_url',
+                  'data_type', 'header', 'description', 'notepad')
 
 
 #
--- a/src/pyams_content/shared/logo/zmi/properties.py	Wed Sep 04 15:56:28 2019 +0200
+++ b/src/pyams_content/shared/logo/zmi/properties.py	Wed Sep 04 15:57:43 2019 +0200
@@ -46,7 +46,8 @@
 class LogoMainPropertiesEditForm(SharedContentPropertiesEditForm):
     """Logo properties edit form"""
 
-    fields = field.Fields(IWfLogo).select('title', 'short_name', 'notepad')
+    interface = IWfLogo
+    fieldnames = ('title', 'short_name', 'notepad')
 
 
 @adapter_config(name='logo-settings',