Updated data types management
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Jul 2018 11:38:37 +0200
changeset 848 a7cfc19b1b1b
parent 847 1f64d5edff11
child 849 a2d6b6b24c4a
Updated data types management
src/pyams_content/shared/common/interfaces/types.py
src/pyams_content/shared/common/types.py
src/pyams_content/shared/common/zmi/types.py
--- a/src/pyams_content/shared/common/interfaces/types.py	Fri Jul 13 09:52:53 2018 +0200
+++ b/src/pyams_content/shared/common/interfaces/types.py	Fri Jul 13 11:38:37 2018 +0200
@@ -33,6 +33,7 @@
 
 ALL_DATA_TYPES_VOCABULARY = 'PyAMS all data types'
 DATA_TYPES_VOCABULARY = 'PyAMS data types'
+DATA_SUBTYPES_VOCABULARY = 'PyAMS data subtypes'
 DATA_TYPE_FIELDS_VOCABULARY = 'PyAMS types interface fields'
 
 
--- a/src/pyams_content/shared/common/types.py	Fri Jul 13 09:52:53 2018 +0200
+++ b/src/pyams_content/shared/common/types.py	Fri Jul 13 11:38:37 2018 +0200
@@ -23,7 +23,7 @@
 from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
 from pyams_content.shared.common.interfaces.types import IDataType, ISubType, IBaseDataType, ITypedSharedTool, \
     ITypedDataManager, DATA_MANAGER_ANNOTATION_KEY, DATA_TYPES_VOCABULARY, DATA_TYPE_FIELDS_VOCABULARY, \
-    IWfTypedSharedContent, ALL_DATA_TYPES_VOCABULARY
+    IWfTypedSharedContent, DATA_SUBTYPES_VOCABULARY
 from pyams_form.interfaces.form import IFormContextPermissionChecker
 from pyams_i18n.interfaces import II18n
 from zope.lifecycleevent.interfaces import IObjectAddedEvent
@@ -148,7 +148,7 @@
 #
 
 @vocabulary_config(name=DATA_TYPES_VOCABULARY)
-class TypedSharedToolDataTypes(SimpleVocabulary):
+class TypedSharedToolDataTypesVocabulary(SimpleVocabulary):
     """Typed shared tool data types vocabulary"""
 
     def __init__(self, context):
@@ -157,14 +157,31 @@
         if parent is not None:
             request = check_request()
             manager = ITypedDataManager(parent)
-            terms = [SimpleTerm(datatype.name,
+            terms = [SimpleTerm(datatype.__name__,
                                 title=II18n(datatype).query_attribute('label', request=request))
                      for datatype in manager.values()]
-        super(TypedSharedToolDataTypes, self).__init__(terms)
+        super(TypedSharedToolDataTypesVocabulary, self).__init__(terms)
+
+
+@vocabulary_config(name=DATA_SUBTYPES_VOCABULARY)
+class TypedSharedToolDataSubtypesVocabulary(SimpleVocabulary):
+    """Typed shared tool data subtypes vocabulary"""
+
+    def __init__(self, context):
+        terms = []
+        if IWfTypedSharedContent.providedBy(context):
+            parent = get_parent(context, ITypedSharedTool)
+            if parent is not None:
+                request = check_request()
+                datatype = ITypedDataManager(parent).get(context.data_type)
+                terms = [SimpleTerm(subtype.__name__,
+                                    title=II18n(subtype).query_attribute('label', request=request))
+                         for subtype in datatype.values()]
+        super(TypedSharedToolDataSubtypesVocabulary, self).__init__(terms)
 
 
 @vocabulary_config(name=DATA_TYPE_FIELDS_VOCABULARY)
-class TypedSharedToolDataTypesFields(SimpleVocabulary):
+class TypedSharedToolDataTypesFieldsVocabulary(SimpleVocabulary):
     """Typed shared tool data types fields vocabulary"""
 
     def __init__(self, context):
@@ -175,4 +192,4 @@
             translate = request.localizer.translate
             terms = [SimpleTerm(name, title=translate(field.title))
                      for name, field in getFieldsInOrder(parent.shared_content_types_fields)]
-        super(TypedSharedToolDataTypesFields, self).__init__(terms)
+        super(TypedSharedToolDataTypesFieldsVocabulary, self).__init__(terms)
--- a/src/pyams_content/shared/common/zmi/types.py	Fri Jul 13 09:52:53 2018 +0200
+++ b/src/pyams_content/shared/common/zmi/types.py	Fri Jul 13 11:38:37 2018 +0200
@@ -9,10 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_content.reference.pictograms.zmi.widget import PictogramSelectFieldWidget
-from pyams_content.shared.common.zmi import SharedContentAddForm
-from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
-from pyams_i18n.widget import I18nSEOTextLineFieldWidget
 
 __docformat__ = 'restructuredtext'
 
@@ -36,9 +32,13 @@
 from z3c.table.interfaces import IValues, IColumn
 
 # import packages
+from pyams_content.reference.pictograms.zmi.widget import PictogramSelectFieldWidget
 from pyams_content.shared.common.types import DataType, SubType
+from pyams_content.shared.common.zmi import SharedContentAddForm
+from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
 from pyams_form.form import AJAXAddForm, ajax_config
 from pyams_form.security import ProtectedFormObjectMixin
+from pyams_i18n.widget import I18nSEOTextLineFieldWidget
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.container import delete_container_element
 from pyams_skin.event import get_json_table_refresh_event
@@ -64,7 +64,7 @@
 
 
 @viewlet_config(name='data-types.menu', context=ITypedSharedTool, layer=IAdminLayer,
-                manager=IPropertiesMenu, permission=MANAGE_TOOL_PERMISSION, weight=10)
+                manager=IPropertiesMenu, permission=MANAGE_TOOL_PERMISSION, weight=5)
 class TypedSharedToolTypesMenu(MenuItem):
     """Typed shared tool types menu"""