src/pyams_content/shared/common/__init__.py
changeset 1280 3e456248baf6
parent 1223 99a4c33e2962
child 1333 e10cf8795ff2
equal deleted inserted replaced
1279:d401c6e56391 1280:3e456248baf6
    24 from zope.intid.interfaces import IIntIds
    24 from zope.intid.interfaces import IIntIds
    25 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    25 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    26 from zope.schema.fieldproperty import FieldProperty
    26 from zope.schema.fieldproperty import FieldProperty
    27 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
    27 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
    28 
    28 
       
    29 from pyams_content import _
    29 from pyams_content.features.checker import BaseContentChecker
    30 from pyams_content.features.checker import BaseContentChecker
    30 from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
    31 from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
    31 from pyams_content.features.review.interfaces import IReviewComments
    32 from pyams_content.features.review.interfaces import IReviewComments
    32 from pyams_content.interfaces import CONTRIBUTOR_ROLE, GUEST_ROLE, IBaseContentInfo, MANAGER_ROLE, OWNER_ROLE, \
    33 from pyams_content.interfaces import CONTRIBUTOR_ROLE, GUEST_ROLE, IBaseContentInfo, MANAGER_ROLE, OWNER_ROLE, \
    33     READER_ROLE
    34     READER_ROLE
    34 from pyams_content.shared.common.interfaces import CONTENT_TYPES_VOCABULARY, IBaseSharedTool, ISharedContent, \
    35 from pyams_content.shared.common.interfaces import CONTENT_TYPES_VOCABULARY, IBaseSharedTool, ISharedContent, \
    35     ISharedSite, IWfSharedContent, IWfSharedContentFactory, IWfSharedContentRoles
    36     ISharedSite, IWfSharedContent, IWfSharedContentFactory, IWfSharedContentRoles, SHARED_CONTENT_TYPES_VOCABULARY
    36 from pyams_i18n.content import I18nManagerMixin
    37 from pyams_i18n.content import I18nManagerMixin
    37 from pyams_i18n.interfaces import II18n, II18nManager
    38 from pyams_i18n.interfaces import II18n, II18nManager
    38 from pyams_portal.interfaces import DESIGNER_ROLE
    39 from pyams_portal.interfaces import DESIGNER_ROLE
    39 from pyams_security.interfaces import IDefaultProtectionPolicy
    40 from pyams_security.interfaces import IDefaultProtectionPolicy
    40 from pyams_security.property import RolePrincipalsFieldProperty
    41 from pyams_security.property import RolePrincipalsFieldProperty
    52 from pyams_utils.vocabulary import vocabulary_config
    53 from pyams_utils.vocabulary import vocabulary_config
    53 from pyams_utils.zodb import volatile_property
    54 from pyams_utils.zodb import volatile_property
    54 from pyams_workflow.interfaces import IObjectClonedEvent, IWorkflow, IWorkflowPublicationSupport, \
    55 from pyams_workflow.interfaces import IObjectClonedEvent, IWorkflow, IWorkflowPublicationSupport, \
    55     IWorkflowTransitionEvent, IWorkflowVersions
    56     IWorkflowTransitionEvent, IWorkflowVersions
    56 
    57 
    57 from pyams_content import _
       
    58 
       
    59 
    58 
    60 @vocabulary_config(name='PyAMS shared sites')
    59 @vocabulary_config(name='PyAMS shared sites')
    61 class SharedSiteVocabulary(SimpleVocabulary):
    60 class SharedSiteVocabulary(SimpleVocabulary):
    62     """Shared sites vocabulary"""
    61     """Shared sites vocabulary"""
    63 
    62 
    73 #
    72 #
    74 # Content types management
    73 # Content types management
    75 #
    74 #
    76 
    75 
    77 CONTENT_TYPES = {}
    76 CONTENT_TYPES = {}
    78 
    77 """Dictionnary of all registered content types"""
    79 
    78 
    80 def register_content_type(content):
    79 IGNORED_CONTENT_TYPES = {}
       
    80 """Dictionnary of all registered *ignored* content types; these content types match custom
       
    81 tools which are handled as shared contents (like forms, images maps or views) but which are
       
    82 not "real" contents."""
       
    83 
       
    84 
       
    85 def register_content_type(content, shared_content=True):
    81     """Register a new content type"""
    86     """Register a new content type"""
    82     CONTENT_TYPES[content.content_type] = content
    87     CONTENT_TYPES[content.content_type] = content
       
    88     if not shared_content:
       
    89         IGNORED_CONTENT_TYPES[content.content_type] = content
    83 
    90 
    84 
    91 
    85 @subscriber(IWSGIApplicationCreatedEvent)
    92 @subscriber(IWSGIApplicationCreatedEvent)
    86 def handle_content_types(event):
    93 def handle_content_types(event):
    87     """Check for content types to un-register"""
    94     """Check for content types to un-register"""
    88     registry = get_current_registry()
    95     registry = get_current_registry()
    89     for key, content in CONTENT_TYPES.copy().items():
    96     for key, content in CONTENT_TYPES.copy().items():
    90         if not asbool(registry.settings.get('pyams_content.register.{0}'.format(key), True)):
    97         if not asbool(registry.settings.get('pyams_content.register.{0}'.format(key), True)):
    91             del CONTENT_TYPES[key]
    98             del CONTENT_TYPES[key]
       
    99             if key in IGNORED_CONTENT_TYPES:
       
   100                 del IGNORED_CONTENT_TYPES[key]
    92 
   101 
    93 
   102 
    94 @vocabulary_config(name=CONTENT_TYPES_VOCABULARY)
   103 @vocabulary_config(name=CONTENT_TYPES_VOCABULARY)
    95 class ContentTypesVocabulary(SimpleVocabulary):
   104 class ContentTypesVocabulary(SimpleVocabulary):
    96     """Content types vocabulary"""
   105     """Content types vocabulary"""
   100         translate = request.localizer.translate
   109         translate = request.localizer.translate
   101         terms = sorted([SimpleTerm(content.content_type, title=translate(content.content_name))
   110         terms = sorted([SimpleTerm(content.content_type, title=translate(content.content_name))
   102                         for content in CONTENT_TYPES.values()],
   111                         for content in CONTENT_TYPES.values()],
   103                        key=lambda x: x.title)
   112                        key=lambda x: x.title)
   104         super(ContentTypesVocabulary, self).__init__(terms)
   113         super(ContentTypesVocabulary, self).__init__(terms)
       
   114 
       
   115 
       
   116 @vocabulary_config(name=SHARED_CONTENT_TYPES_VOCABULARY)
       
   117 class SharedContentTypesVocabulary(SimpleVocabulary):
       
   118     """Shared content types vocabulary"""
       
   119 
       
   120     def __init__(self, context):
       
   121         request = check_request()
       
   122         translate = request.localizer.translate
       
   123         terms = sorted([SimpleTerm(content.content_type, title=translate(content.content_name))
       
   124                         for content in CONTENT_TYPES.values()
       
   125                         if content.content_type not in IGNORED_CONTENT_TYPES],
       
   126                        key=lambda x: x.title)
       
   127         super(SharedContentTypesVocabulary, self).__init__(terms)
   105 
   128 
   106 
   129 
   107 #
   130 #
   108 # Workflow shared content class and adapters
   131 # Workflow shared content class and adapters
   109 #
   132 #