src/pyams_content/shared/common/types.py
changeset 848 a7cfc19b1b1b
parent 833 987838f48783
child 854 d9c216572b6b
--- 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)