Added optional data type to shared resources
authorThierry Florac <thierry.florac@onf.fr>
Mon, 13 May 2019 17:37:49 +0200
changeset 1310 2302a43f55b0
parent 1309 82c60033f08e
child 1311 d643d60aa096
Added optional data type to shared resources
src/pyams_content/shared/topic/__init__.py
src/pyams_content/shared/topic/interfaces.py
src/pyams_content/shared/topic/manager.py
src/pyams_content/shared/topic/zmi/__init__.py
--- a/src/pyams_content/shared/topic/__init__.py	Mon May 13 17:36:03 2019 +0200
+++ b/src/pyams_content/shared/topic/__init__.py	Mon May 13 17:37:49 2019 +0200
@@ -20,8 +20,9 @@
 from pyams_content.component.theme.interfaces import ITagsTarget, IThemesTarget
 from pyams_content.features.preview.interfaces import IPreviewTarget
 from pyams_content.features.review.interfaces import IReviewTarget
-from pyams_content.shared.common import SharedContent, WfSharedContent, register_content_type
+from pyams_content.shared.common import SharedContent, register_content_type
 from pyams_content.shared.common.interfaces import IWfSharedContentFactory
+from pyams_content.shared.common.types import WfTypedSharedContent
 from pyams_content.shared.topic.interfaces import ITopic, IWfTopic, IWfTopicFactory, TOPIC_CONTENT_NAME, \
     TOPIC_CONTENT_TYPE
 from pyams_utils.adapter import adapter_config
@@ -29,13 +30,14 @@
 
 @implementer(IWfTopic, IIllustrationTarget, ILinkIllustrationTarget, IParagraphContainerTarget,
              ITagsTarget, IThemesTarget, IPreviewTarget, IReviewTarget)
-class WfTopic(WfSharedContent):
+class WfTopic(WfTypedSharedContent):
     """Base topic"""
 
     content_type = TOPIC_CONTENT_TYPE
     content_name = TOPIC_CONTENT_NAME
 
     references = FieldProperty(IWfTopic['references'])
+    data_type = FieldProperty(IWfTopic['data_type'])
 
 register_content_type(WfTopic)
 
--- a/src/pyams_content/shared/topic/interfaces.py	Mon May 13 17:36:03 2019 +0200
+++ b/src/pyams_content/shared/topic/interfaces.py	Mon May 13 17:37:49 2019 +0200
@@ -13,18 +13,21 @@
 __docformat__ = 'restructuredtext'
 
 from zope.interface import Interface
+from zope.schema import Choice
+
+from pyams_content.shared.common.interfaces import ISharedContent
+from pyams_content.shared.common.interfaces.types import ITypedSharedToolPortalContext, \
+    IWfTypedSharedContentPortalContext, DATA_TYPES_VOCABULARY
+from pyams_sequence.interfaces import IInternalReferencesList
 
 from pyams_content import _
-from pyams_content.shared.common.interfaces import ISharedContent, ISharedToolPortalContext, \
-    IWfSharedContentPortalContext
-from pyams_sequence.interfaces import IInternalReferencesList
 
 
 TOPIC_CONTENT_TYPE = 'topic'
 TOPIC_CONTENT_NAME = _("Topic")
 
 
-class ITopicManager(ISharedToolPortalContext):
+class ITopicManager(ITypedSharedToolPortalContext):
     """Topic manager interface"""
 
 
@@ -32,9 +35,14 @@
     """Topic manager factory interface"""
 
 
-class IWfTopic(IWfSharedContentPortalContext, IInternalReferencesList):
+class IWfTopic(IWfTypedSharedContentPortalContext, IInternalReferencesList):
     """Topic interface"""
 
+    data_type = Choice(title=_("Data type"),
+                       description=_("Type of content data"),
+                       required=False,
+                       vocabulary=DATA_TYPES_VOCABULARY)
+
 
 class IWfTopicFactory(Interface):
     """Topic parent interface"""
--- a/src/pyams_content/shared/topic/manager.py	Mon May 13 17:36:03 2019 +0200
+++ b/src/pyams_content/shared/topic/manager.py	Mon May 13 17:37:49 2019 +0200
@@ -22,7 +22,7 @@
 from pyams_content.component.theme.interfaces import IThemesManagerTarget
 from pyams_content.reference.pictograms.interfaces import IPictogramManagerTarget
 from pyams_content.shared.common.interfaces import ISharedContentFactory
-from pyams_content.shared.common.manager import SharedTool
+from pyams_content.shared.common.types import TypedSharedTool
 from pyams_content.shared.topic import Topic
 from pyams_content.shared.topic.interfaces import ITopicManager, ITopicManagerFactory, TOPIC_CONTENT_TYPE
 from pyams_utils.adapter import adapter_config
@@ -31,7 +31,7 @@
 
 
 @implementer(ITopicManager, IParagraphFactorySettings, IThemesManagerTarget, IPictogramManagerTarget)
-class TopicManager(SharedTool):
+class TopicManager(TypedSharedTool):
     """Topic manager class"""
 
     shared_content_type = TOPIC_CONTENT_TYPE
--- a/src/pyams_content/shared/topic/zmi/__init__.py	Mon May 13 17:36:03 2019 +0200
+++ b/src/pyams_content/shared/topic/zmi/__init__.py	Mon May 13 17:37:49 2019 +0200
@@ -12,13 +12,14 @@
 
 __docformat__ = 'restructuredtext'
 
-from pyramid.view import view_config
+from z3c.form import field
 from zope.interface import Interface
 
-from pyams_content import _
-from pyams_content.interfaces import CREATE_CONTENT_PERMISSION
-from pyams_content.shared.common.zmi import SharedContentAJAXAddForm, SharedContentAddForm
+from pyams_content.interfaces import CREATE_CONTENT_PERMISSION, MANAGE_CONTENT_PERMISSION
+from pyams_content.shared.common.zmi import SharedContentAJAXAddForm
+from pyams_content.shared.common.zmi.types import TypedSharedContentAddForm, TypedSharedContentPropertiesEditForm
 from pyams_content.shared.topic.interfaces import ITopicManager, IWfTopic
+from pyams_form.form import ajax_config
 from pyams_i18n.interfaces import II18n
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.interfaces import IContentTitle
@@ -30,6 +31,8 @@
 from pyams_zmi.interfaces.menu import IContentManagementMenu
 from pyams_zmi.layer import IAdminLayer
 
+from pyams_content import _
+
 
 @adapter_config(context=(IWfTopic, IContentManagementMenu), provides=IMenuHeader)
 class TopicContentMenuHeader(ContextRequestAdapter):
@@ -62,13 +65,21 @@
 
 @pagelet_config(name='add-shared-content.html', context=ITopicManager, layer=IPyAMSLayer,
                 permission=CREATE_CONTENT_PERMISSION)
-class TopicAddForm(SharedContentAddForm):
+@ajax_config(name='add-shared-content.json', context=ITopicManager, layer=IPyAMSLayer,
+             permission=CREATE_CONTENT_PERMISSION, base=SharedContentAJAXAddForm)
+class TopicAddForm(TypedSharedContentAddForm):
     """Topic add form"""
 
     legend = _("Add topic")
 
+    fields = field.Fields(IWfTopic).select('title', 'data_type', 'notepad')
 
-@view_config(name='add-shared-content.json', context=ITopicManager, request_type=IPyAMSLayer,
-             permission=CREATE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class TopicAJAXAddForm(SharedContentAJAXAddForm, TopicAddForm):
-    """Topic add form, JSON renderer"""
+
+@pagelet_config(name='properties.html', context=IWfTopic, layer=IPyAMSLayer,
+                permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='properties.json', context=IWfTopic, layer=IPyAMSLayer,
+             permission=MANAGE_CONTENT_PERMISSION)
+class TopicPropertiesEditForm(TypedSharedContentPropertiesEditForm):
+    """Topic properties edit form"""
+
+    interface = IWfTopic