--- a/src/pyams_content/shared/common/interfaces/types.py Wed Jul 11 15:11:45 2018 +0200
+++ b/src/pyams_content/shared/common/interfaces/types.py Wed Jul 11 15:22:16 2018 +0200
@@ -16,13 +16,14 @@
# import standard library
# import interfaces
-from pyams_content.shared.common.interfaces import ISharedTool
+from pyams_content.reference.pictograms.interfaces import PICTOGRAM_VOCABULARY
+from pyams_content.shared.common.interfaces import ISharedTool, IWfSharedContent, IBaseContentPortalContext
from pyams_portal.interfaces import IPortalContext
from zope.container.interfaces import IContainer
from zope.location.interfaces import ILocation
# import packages
-from pyams_i18n.schema import I18nTextLineField, I18nThumbnailImageField
+from pyams_i18n.schema import I18nTextLineField
from zope.container.constraints import contains
from zope.interface import Attribute
from zope.schema import TextLine, List, Choice
@@ -30,6 +31,11 @@
from pyams_content import _
+ALL_DATA_TYPES_VOCABULARY = 'PyAMS all data types'
+DATA_TYPES_VOCABULARY = 'PyAMS data types'
+DATA_TYPE_FIELDS_VOCABULARY = 'PyAMS types interface fields'
+
+
class IBaseDataType(ILocation):
"""Data interface for data-types and sub-types"""
@@ -65,9 +71,10 @@
description=_("Label used to announce next date for this type"),
required=False)
- pictogram = I18nThumbnailImageField(title=_("Pictogram"),
- description=_("Image associated to this data type"),
- required=False)
+ pictogram = Choice(title=_("Pictogram"),
+ description=_("Pictogram associated with this data type"),
+ vocabulary=PICTOGRAM_VOCABULARY,
+ required=False)
class ISubType(IBaseDataType):
@@ -81,7 +88,7 @@
field_names = List(title=_("Field names"),
description=_("List of fields associated with this data type"),
- value_type=Choice(vocabulary='PyAMS types interface fields'))
+ value_type=Choice(vocabulary=DATA_TYPE_FIELDS_VOCABULARY))
#
@@ -105,3 +112,23 @@
class ITypedSharedToolPortalContext(ITypedSharedTool, IPortalContext):
"""Typed shared tool with portal context"""
+
+
+#
+# Typed content interfaces
+#
+
+class IWfTypedSharedContent(IWfSharedContent):
+ """Typed shared content"""
+
+ data_type = Choice(title=_("Data type"),
+ description=_("Type of content data"),
+ required=True,
+ vocabulary=DATA_TYPES_VOCABULARY)
+
+ def get_data_type(self):
+ """Get associated data type"""
+
+
+class IWfTypedSharedContentPortalContext(IWfTypedSharedContent, IBaseContentPortalContext):
+ """Shared content with portal support"""
--- a/src/pyams_content/shared/common/types.py Wed Jul 11 15:11:45 2018 +0200
+++ b/src/pyams_content/shared/common/types.py Wed Jul 11 15:22:16 2018 +0200
@@ -19,22 +19,26 @@
from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
from pyams_content.component.links.interfaces import ILinkContainerTarget
from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
-from pyams_content.component.theme.interfaces import IThemesTarget
+from pyams_content.component.theme.interfaces import IThemesTarget, IThemesInfo
from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
from pyams_content.shared.common.interfaces.types import IDataType, ISubType, IBaseDataType, ITypedSharedTool, \
- ITypedDataManager, DATA_MANAGER_ANNOTATION_KEY
+ ITypedDataManager, DATA_MANAGER_ANNOTATION_KEY, DATA_TYPES_VOCABULARY, DATA_TYPE_FIELDS_VOCABULARY, \
+ IWfTypedSharedContent, ALL_DATA_TYPES_VOCABULARY
from pyams_form.interfaces.form import IFormContextPermissionChecker
+from pyams_i18n.interfaces import II18n
+from zope.lifecycleevent.interfaces import IObjectAddedEvent
from zope.location.interfaces import ISublocations
from zope.traversing.interfaces import ITraversable
# import packages
from persistent import Persistent
+from pyams_content.shared.common import WfSharedContent
from pyams_content.shared.common.manager import SharedTool
-from pyams_i18n.property import I18nFileProperty
from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
from pyams_utils.request import check_request
from pyams_utils.traversing import get_parent
from pyams_utils.vocabulary import vocabulary_config
+from pyramid.events import subscriber
from zope.container.contained import Contained
from zope.container.ordered import OrderedContainer
from zope.interface import implementer
@@ -53,7 +57,7 @@
single_label = FieldProperty(IBaseDataType['single_label'])
seeall_label = FieldProperty(IBaseDataType['seeall_label'])
next_label = FieldProperty(IBaseDataType['next_label'])
- pictogram = I18nFileProperty(IBaseDataType['pictogram'])
+ pictogram = FieldProperty(IBaseDataType['pictogram'])
@implementer(ISubType, IParagraphContainerTarget, IExtFileContainerTarget, ILinkContainerTarget)
@@ -109,14 +113,64 @@
return ITypedDataManager(self.context).values()
-@vocabulary_config(name='PyAMS types interface fields')
+#
+# Typed shared content
+#
+
+@implementer(IWfTypedSharedContent)
+class WfTypedSharedContent(WfSharedContent):
+ """Typed shared content"""
+
+ data_type = FieldProperty(IWfTypedSharedContent['data_type'])
+
+ def get_data_type(self):
+ if not self.data_type:
+ return None
+ tool = get_parent(self, ITypedSharedTool)
+ if tool is not None:
+ manager = ITypedDataManager(tool)
+ return manager.get(self.data_type)
+
+
+@subscriber(IObjectAddedEvent, context_selector=IWfTypedSharedContent)
+def handle_added_typed_shared_content(event):
+ """Automatically assign themes for newly created contents"""
+ content = event.object
+ if not IThemesTarget.providedBy(content):
+ return
+ data_type = content.get_data_type()
+ if data_type is not None:
+ IThemesInfo(content).themes = IThemesInfo(data_type).themes
+
+
+#
+# Data types vocabularies
+#
+
+@vocabulary_config(name=DATA_TYPES_VOCABULARY)
+class TypedSharedToolDataTypes(SimpleVocabulary):
+ """Typed shared tool data types vocabulary"""
+
+ def __init__(self, context):
+ terms = []
+ parent = get_parent(context, ITypedSharedTool)
+ if parent is not None:
+ request = check_request()
+ manager = ITypedDataManager(parent)
+ terms = [SimpleTerm(datatype.name,
+ title=II18n(datatype).query_attribute('label', request=request))
+ for datatype in manager.values()]
+ super(TypedSharedToolDataTypes, self).__init__(terms)
+
+
+@vocabulary_config(name=DATA_TYPE_FIELDS_VOCABULARY)
class TypedSharedToolDataTypesFields(SimpleVocabulary):
"""Typed shared tool data types fields vocabulary"""
def __init__(self, context):
terms = []
parent = get_parent(context, ITypedSharedTool)
- if parent is not None:
+ if (parent is not None) and parent.shared_content_types_fields:
request = check_request()
translate = request.localizer.translate
terms = [SimpleTerm(name, title=translate(field.title))
--- a/src/pyams_content/shared/common/zmi/types.py Wed Jul 11 15:11:45 2018 +0200
+++ b/src/pyams_content/shared/common/zmi/types.py Wed Jul 11 15:22:16 2018 +0200
@@ -9,6 +9,10 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from pyams_content.reference.pictograms.zmi.widget import PictogramSelectFieldWidget
+from pyams_content.shared.common.zmi import SharedContentAddForm
+from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
+from pyams_i18n.widget import I18nSEOTextLineFieldWidget
__docformat__ = 'restructuredtext'
@@ -17,9 +21,9 @@
import json
# import interfaces
-from pyams_content.interfaces import MANAGE_TOOL_PERMISSION
+from pyams_content.interfaces import MANAGE_TOOL_PERMISSION, MANAGE_CONTENT_PERMISSION
from pyams_content.shared.common.interfaces.types import ITypedSharedTool, ITypedDataManager, \
- IBaseDataType, IDataType, ISubType
+ IBaseDataType, IDataType, ISubType, IWfTypedSharedContent
from pyams_content.skin import pyams_content
from pyams_i18n.interfaces import II18n
from pyams_skin.interfaces.container import ITableElementName
@@ -266,7 +270,13 @@
label_css_class = 'control-label col-md-4'
input_css_class = 'col-md-8'
- fields = field.Fields(IDataType).omit('__parent__', '__name__')
+ @property
+ def fields(self):
+ fields = field.Fields(IDataType).omit('__parent__', '__name__')
+ fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
+ if not self.context.shared_content_types_fields:
+ fields = fields.omit('field_names')
+ return fields
edit_permission = MANAGE_TOOL_PERMISSION
@@ -303,7 +313,14 @@
label_css_class = 'control-label col-md-4'
input_css_class = 'col-md-8'
- fields = field.Fields(IDataType).omit('__parent__', '__name__')
+ @property
+ def fields(self):
+ fields = field.Fields(IDataType).omit('__parent__', '__name__')
+ fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
+ tool = get_parent(self.context, ITypedSharedTool)
+ if not tool.shared_content_types_fields:
+ fields = fields.omit('field_names')
+ return fields
edit_permission = MANAGE_TOOL_PERMISSION
@@ -471,6 +488,7 @@
input_css_class = 'col-md-8'
fields = field.Fields(ISubType).omit('__parent__', '__name__')
+ fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
edit_permission = MANAGE_TOOL_PERMISSION
@@ -517,6 +535,7 @@
input_css_class = 'col-md-8'
fields = field.Fields(ISubType).omit('__parent__', '__name__')
+ fields['pictogram'].widgetFactory = PictogramSelectFieldWidget
edit_permission = MANAGE_TOOL_PERMISSION
@@ -537,3 +556,25 @@
}
else:
return super(self.__class__, self).get_ajax_output(changes)
+
+
+#
+# Typed shared content views
+#
+
+class TypedSharedContentAddForm(SharedContentAddForm):
+ """Typed shared content add form"""
+
+ fields = field.Fields(IWfTypedSharedContent).select('title', 'data_type', 'notepad')
+
+
+@pagelet_config(name='properties.html', context=IWfTypedSharedContent, layer=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='properties.json', context=IWfTypedSharedContent, layer=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION)
+class TypedSharedContentProperteisEditForm(SharedContentPropertiesEditForm):
+ """Typed shared content properties edit form"""
+
+ fields = field.Fields(IWfTypedSharedContent).select('title', 'short_name', 'content_url',
+ 'data_type', 'description', 'notepad')
+ fields['title'].widgetFactory = I18nSEOTextLineFieldWidget