Added vocabulary to display only shared content types
authorThierry Florac <tflorac@ulthar.net>
Fri, 15 Feb 2019 12:53:15 +0100
changeset 1280 3e456248baf6
parent 1279 d401c6e56391
child 1281 327666db65f9
Added vocabulary to display only shared content types
src/pyams_content/shared/common/__init__.py
src/pyams_content/shared/common/interfaces/__init__.py
--- a/src/pyams_content/shared/common/__init__.py	Thu Feb 14 17:44:38 2019 +0100
+++ b/src/pyams_content/shared/common/__init__.py	Fri Feb 15 12:53:15 2019 +0100
@@ -26,13 +26,14 @@
 from zope.schema.fieldproperty import FieldProperty
 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
+from pyams_content import _
 from pyams_content.features.checker import BaseContentChecker
 from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
 from pyams_content.features.review.interfaces import IReviewComments
 from pyams_content.interfaces import CONTRIBUTOR_ROLE, GUEST_ROLE, IBaseContentInfo, MANAGER_ROLE, OWNER_ROLE, \
     READER_ROLE
 from pyams_content.shared.common.interfaces import CONTENT_TYPES_VOCABULARY, IBaseSharedTool, ISharedContent, \
-    ISharedSite, IWfSharedContent, IWfSharedContentFactory, IWfSharedContentRoles
+    ISharedSite, IWfSharedContent, IWfSharedContentFactory, IWfSharedContentRoles, SHARED_CONTENT_TYPES_VOCABULARY
 from pyams_i18n.content import I18nManagerMixin
 from pyams_i18n.interfaces import II18n, II18nManager
 from pyams_portal.interfaces import DESIGNER_ROLE
@@ -54,8 +55,6 @@
 from pyams_workflow.interfaces import IObjectClonedEvent, IWorkflow, IWorkflowPublicationSupport, \
     IWorkflowTransitionEvent, IWorkflowVersions
 
-from pyams_content import _
-
 
 @vocabulary_config(name='PyAMS shared sites')
 class SharedSiteVocabulary(SimpleVocabulary):
@@ -75,11 +74,19 @@
 #
 
 CONTENT_TYPES = {}
+"""Dictionnary of all registered content types"""
+
+IGNORED_CONTENT_TYPES = {}
+"""Dictionnary of all registered *ignored* content types; these content types match custom
+tools which are handled as shared contents (like forms, images maps or views) but which are
+not "real" contents."""
 
 
-def register_content_type(content):
+def register_content_type(content, shared_content=True):
     """Register a new content type"""
     CONTENT_TYPES[content.content_type] = content
+    if not shared_content:
+        IGNORED_CONTENT_TYPES[content.content_type] = content
 
 
 @subscriber(IWSGIApplicationCreatedEvent)
@@ -89,6 +96,8 @@
     for key, content in CONTENT_TYPES.copy().items():
         if not asbool(registry.settings.get('pyams_content.register.{0}'.format(key), True)):
             del CONTENT_TYPES[key]
+            if key in IGNORED_CONTENT_TYPES:
+                del IGNORED_CONTENT_TYPES[key]
 
 
 @vocabulary_config(name=CONTENT_TYPES_VOCABULARY)
@@ -104,6 +113,20 @@
         super(ContentTypesVocabulary, self).__init__(terms)
 
 
+@vocabulary_config(name=SHARED_CONTENT_TYPES_VOCABULARY)
+class SharedContentTypesVocabulary(SimpleVocabulary):
+    """Shared content types vocabulary"""
+
+    def __init__(self, context):
+        request = check_request()
+        translate = request.localizer.translate
+        terms = sorted([SimpleTerm(content.content_type, title=translate(content.content_name))
+                        for content in CONTENT_TYPES.values()
+                        if content.content_type not in IGNORED_CONTENT_TYPES],
+                       key=lambda x: x.title)
+        super(SharedContentTypesVocabulary, self).__init__(terms)
+
+
 #
 # Workflow shared content class and adapters
 #
--- a/src/pyams_content/shared/common/interfaces/__init__.py	Thu Feb 14 17:44:38 2019 +0100
+++ b/src/pyams_content/shared/common/interfaces/__init__.py	Fri Feb 15 12:53:15 2019 +0100
@@ -14,19 +14,18 @@
 
 from zope.container.constraints import containers, contains
 from zope.container.interfaces import IContainer
-from zope.interface import Interface, Attribute
-from zope.schema import Choice, Bool, Text, TextLine
+from zope.interface import Attribute, Interface
+from zope.schema import Bool, Choice, Text, TextLine
 
-from pyams_content.interfaces import IBaseContent, MANAGE_CONTENT_PERMISSION, OWNER_ROLE, MANAGER_ROLE, \
-    READER_ROLE, GUEST_ROLE, WEBMASTER_ROLE, PILOT_ROLE, CONTRIBUTOR_ROLE
+from pyams_content import _
+from pyams_content.interfaces import CONTRIBUTOR_ROLE, GUEST_ROLE, IBaseContent, MANAGER_ROLE, \
+    MANAGE_CONTENT_PERMISSION, OWNER_ROLE, PILOT_ROLE, READER_ROLE, WEBMASTER_ROLE
 from pyams_i18n.schema import I18nTextField
-from pyams_portal.interfaces import IPortalContext, DESIGNER_ROLE
+from pyams_portal.interfaces import DESIGNER_ROLE, IPortalContext
 from pyams_security.schema import Principal, PrincipalsSet
 from pyams_utils.schema import TextLineListField
 from pyams_workflow.interfaces import IWorkflowManagedContent
 
-from pyams_content import _
-
 
 class IDeletableElement(Interface):
     """Deletable element interface"""
@@ -234,6 +233,8 @@
 
 CONTENT_TYPES_VOCABULARY = 'PyAMS content types'
 
+SHARED_CONTENT_TYPES_VOCABULARY = 'PyAMS shared content types'
+
 
 #
 # Generic restrictions interfaces