22 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedContent, ISharedTool |
22 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedContent, ISharedTool |
23 from pyams_security.interfaces import IDefaultProtectionPolicy |
23 from pyams_security.interfaces import IDefaultProtectionPolicy |
24 from pyams_sequence.interfaces import ISequentialIdTarget, ISequentialIdInfo |
24 from pyams_sequence.interfaces import ISequentialIdTarget, ISequentialIdInfo |
25 from pyams_utils.interfaces import VIEW_PERMISSION |
25 from pyams_utils.interfaces import VIEW_PERMISSION |
26 from pyams_workflow.interfaces import IWorkflowPublicationSupport, IWorkflow, IObjectClonedEvent, IWorkflowVersions |
26 from pyams_workflow.interfaces import IWorkflowPublicationSupport, IWorkflow, IObjectClonedEvent, IWorkflowVersions |
|
27 from pyramid.interfaces import IWSGIApplicationCreatedEvent |
27 from zope.dublincore.interfaces import IZopeDublinCore |
28 from zope.dublincore.interfaces import IZopeDublinCore |
28 from zope.intid.interfaces import IIntIds |
29 from zope.intid.interfaces import IIntIds |
29 from zope.lifecycleevent.interfaces import IObjectModifiedEvent |
30 from zope.lifecycleevent.interfaces import IObjectModifiedEvent |
30 |
31 |
31 # import packages |
32 # import packages |
33 from pyams_i18n.content import I18nManagerMixin |
34 from pyams_i18n.content import I18nManagerMixin |
34 from pyams_security.property import RolePrincipalsFieldProperty |
35 from pyams_security.property import RolePrincipalsFieldProperty |
35 from pyams_security.security import ProtectedObject |
36 from pyams_security.security import ProtectedObject |
36 from pyams_utils.adapter import adapter_config, ContextAdapter |
37 from pyams_utils.adapter import adapter_config, ContextAdapter |
37 from pyams_utils.registry import query_utility |
38 from pyams_utils.registry import query_utility |
38 from pyams_utils.request import query_request |
39 from pyams_utils.request import query_request, check_request |
39 from pyams_utils.traversing import get_parent |
40 from pyams_utils.traversing import get_parent |
|
41 from pyams_utils.vocabulary import vocabulary_config |
40 from pyramid.events import subscriber |
42 from pyramid.events import subscriber |
|
43 from pyramid.settings import asbool |
|
44 from pyramid.threadlocal import get_current_registry |
41 from zope.container.contained import Contained |
45 from zope.container.contained import Contained |
42 from zope.interface import implementer |
46 from zope.interface import implementer |
43 from zope.schema.fieldproperty import FieldProperty |
47 from zope.schema.fieldproperty import FieldProperty |
|
48 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
44 |
49 |
45 |
50 |
46 # |
51 # |
47 # Content types management |
52 # Content types management |
48 # |
53 # |
51 |
56 |
52 |
57 |
53 def register_content_type(content): |
58 def register_content_type(content): |
54 """Register a new content type""" |
59 """Register a new content type""" |
55 CONTENT_TYPES[content.content_type] = content |
60 CONTENT_TYPES[content.content_type] = content |
|
61 |
|
62 |
|
63 @subscriber(IWSGIApplicationCreatedEvent) |
|
64 def handle_content_types(event): |
|
65 """Check for content types to un-register""" |
|
66 registry = get_current_registry() |
|
67 for key, content in CONTENT_TYPES.copy().items(): |
|
68 if not asbool(registry.settings.get('pyams_content.register.{0}'.format(key), True)): |
|
69 del CONTENT_TYPES[key] |
|
70 |
|
71 |
|
72 @vocabulary_config(name='PyAMS content types') |
|
73 class ContentTypesVocabulary(SimpleVocabulary): |
|
74 """Content types vocabulary""" |
|
75 |
|
76 def __init__(self, context): |
|
77 request = check_request() |
|
78 translate = request.localizer.translate |
|
79 terms = [SimpleTerm(content.content_type, title=translate(content.content_name)) |
|
80 for content in CONTENT_TYPES.values()] |
|
81 super(ContentTypesVocabulary, self).__init__(terms) |
56 |
82 |
57 |
83 |
58 # |
84 # |
59 # Workflow shared content class and adapters |
85 # Workflow shared content class and adapters |
60 # |
86 # |