src/pyams_content/shared/common/types.py
changeset 848 a7cfc19b1b1b
parent 833 987838f48783
child 854 d9c216572b6b
equal deleted inserted replaced
847:1f64d5edff11 848:a7cfc19b1b1b
    21 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
    21 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
    22 from pyams_content.component.theme.interfaces import IThemesTarget, IThemesInfo
    22 from pyams_content.component.theme.interfaces import IThemesTarget, IThemesInfo
    23 from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
    23 from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
    24 from pyams_content.shared.common.interfaces.types import IDataType, ISubType, IBaseDataType, ITypedSharedTool, \
    24 from pyams_content.shared.common.interfaces.types import IDataType, ISubType, IBaseDataType, ITypedSharedTool, \
    25     ITypedDataManager, DATA_MANAGER_ANNOTATION_KEY, DATA_TYPES_VOCABULARY, DATA_TYPE_FIELDS_VOCABULARY, \
    25     ITypedDataManager, DATA_MANAGER_ANNOTATION_KEY, DATA_TYPES_VOCABULARY, DATA_TYPE_FIELDS_VOCABULARY, \
    26     IWfTypedSharedContent, ALL_DATA_TYPES_VOCABULARY
    26     IWfTypedSharedContent, DATA_SUBTYPES_VOCABULARY
    27 from pyams_form.interfaces.form import IFormContextPermissionChecker
    27 from pyams_form.interfaces.form import IFormContextPermissionChecker
    28 from pyams_i18n.interfaces import II18n
    28 from pyams_i18n.interfaces import II18n
    29 from zope.lifecycleevent.interfaces import IObjectAddedEvent
    29 from zope.lifecycleevent.interfaces import IObjectAddedEvent
    30 from zope.location.interfaces import ISublocations
    30 from zope.location.interfaces import ISublocations
    31 from zope.traversing.interfaces import ITraversable
    31 from zope.traversing.interfaces import ITraversable
   146 #
   146 #
   147 # Data types vocabularies
   147 # Data types vocabularies
   148 #
   148 #
   149 
   149 
   150 @vocabulary_config(name=DATA_TYPES_VOCABULARY)
   150 @vocabulary_config(name=DATA_TYPES_VOCABULARY)
   151 class TypedSharedToolDataTypes(SimpleVocabulary):
   151 class TypedSharedToolDataTypesVocabulary(SimpleVocabulary):
   152     """Typed shared tool data types vocabulary"""
   152     """Typed shared tool data types vocabulary"""
   153 
   153 
   154     def __init__(self, context):
   154     def __init__(self, context):
   155         terms = []
   155         terms = []
   156         parent = get_parent(context, ITypedSharedTool)
   156         parent = get_parent(context, ITypedSharedTool)
   157         if parent is not None:
   157         if parent is not None:
   158             request = check_request()
   158             request = check_request()
   159             manager = ITypedDataManager(parent)
   159             manager = ITypedDataManager(parent)
   160             terms = [SimpleTerm(datatype.name,
   160             terms = [SimpleTerm(datatype.__name__,
   161                                 title=II18n(datatype).query_attribute('label', request=request))
   161                                 title=II18n(datatype).query_attribute('label', request=request))
   162                      for datatype in manager.values()]
   162                      for datatype in manager.values()]
   163         super(TypedSharedToolDataTypes, self).__init__(terms)
   163         super(TypedSharedToolDataTypesVocabulary, self).__init__(terms)
       
   164 
       
   165 
       
   166 @vocabulary_config(name=DATA_SUBTYPES_VOCABULARY)
       
   167 class TypedSharedToolDataSubtypesVocabulary(SimpleVocabulary):
       
   168     """Typed shared tool data subtypes vocabulary"""
       
   169 
       
   170     def __init__(self, context):
       
   171         terms = []
       
   172         if IWfTypedSharedContent.providedBy(context):
       
   173             parent = get_parent(context, ITypedSharedTool)
       
   174             if parent is not None:
       
   175                 request = check_request()
       
   176                 datatype = ITypedDataManager(parent).get(context.data_type)
       
   177                 terms = [SimpleTerm(subtype.__name__,
       
   178                                     title=II18n(subtype).query_attribute('label', request=request))
       
   179                          for subtype in datatype.values()]
       
   180         super(TypedSharedToolDataSubtypesVocabulary, self).__init__(terms)
   164 
   181 
   165 
   182 
   166 @vocabulary_config(name=DATA_TYPE_FIELDS_VOCABULARY)
   183 @vocabulary_config(name=DATA_TYPE_FIELDS_VOCABULARY)
   167 class TypedSharedToolDataTypesFields(SimpleVocabulary):
   184 class TypedSharedToolDataTypesFieldsVocabulary(SimpleVocabulary):
   168     """Typed shared tool data types fields vocabulary"""
   185     """Typed shared tool data types fields vocabulary"""
   169 
   186 
   170     def __init__(self, context):
   187     def __init__(self, context):
   171         terms = []
   188         terms = []
   172         parent = get_parent(context, ITypedSharedTool)
   189         parent = get_parent(context, ITypedSharedTool)
   173         if (parent is not None) and parent.shared_content_types_fields:
   190         if (parent is not None) and parent.shared_content_types_fields:
   174             request = check_request()
   191             request = check_request()
   175             translate = request.localizer.translate
   192             translate = request.localizer.translate
   176             terms = [SimpleTerm(name, title=translate(field.title))
   193             terms = [SimpleTerm(name, title=translate(field.title))
   177                      for name, field in getFieldsInOrder(parent.shared_content_types_fields)]
   194                      for name, field in getFieldsInOrder(parent.shared_content_types_fields)]
   178         super(TypedSharedToolDataTypesFields, self).__init__(terms)
   195         super(TypedSharedToolDataTypesFieldsVocabulary, self).__init__(terms)