src/pyams_content/component/paragraph/__init__.py
changeset 241 50452584f7ae
parent 183 6a4964dad8aa
child 355 5dce53509832
--- a/src/pyams_content/component/paragraph/__init__.py	Fri Nov 10 11:47:23 2017 +0100
+++ b/src/pyams_content/component/paragraph/__init__.py	Fri Nov 10 11:47:59 2017 +0100
@@ -20,11 +20,13 @@
     IParagraphContainer, IParagraphFactorySettings
 from pyams_content.shared.common.interfaces import IWfSharedContent
 from pyams_form.interfaces.form import IFormContextPermissionChecker
+from pyams_i18n.interfaces import II18n
 from pyams_workflow.interfaces import IWorkflowState
 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
 
 # import packages
 from persistent import Persistent
+from pyams_content.features.checker import BaseContentChecker
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.registry import query_utility
 from pyams_utils.request import check_request
@@ -76,6 +78,17 @@
     title = FieldProperty(IBaseParagraph['title'])
 
 
+class BaseParagraphContentChecker(BaseContentChecker):
+    """Base paragraph content checker mixin"""
+
+    @property
+    def label(self):
+        request = check_request()
+        translate = request.localizer.translate
+        return II18n(self.context).query_attribute('title', request) or \
+            '({0})'.format(translate(self.context.icon_hint).lower())
+
+
 @vocabulary_config(name='PyAMS paragraph factories')
 class ParagraphFactoriesVocabulary(SimpleVocabulary):
     """Paragraph factories vocabulary"""
@@ -96,14 +109,14 @@
 
     @property
     def edit_permission(self):
-        content = get_parent(self.context, IWfSharedContent)
+        content = get_parent(self.context, IParagraphContainerTarget)
         return IFormContextPermissionChecker(content).edit_permission
 
 
 @subscriber(IObjectAddedEvent, context_selector=IBaseParagraph)
 def handle_added_paragraph(event):
     """Handle added paragraph"""
-    content = get_parent(event.object, IWfSharedContent)
+    content = get_parent(event.object, IParagraphContainerTarget)
     if content is not None:
         get_current_registry().notify(ObjectModifiedEvent(content))
 
@@ -111,7 +124,7 @@
 @subscriber(IObjectModifiedEvent, context_selector=IBaseParagraph)
 def handle_modified_paragraph(event):
     """Handle modified paragraph"""
-    content = get_parent(event.object, IWfSharedContent)
+    content = get_parent(event.object, IParagraphContainerTarget)
     if content is not None:
         get_current_registry().notify(ObjectModifiedEvent(content))
 
@@ -119,6 +132,6 @@
 @subscriber(IObjectRemovedEvent, context_selector=IBaseParagraph)
 def handle_removed_paragraph(event):
     """Handle removed paragraph"""
-    content = get_parent(event.object, IWfSharedContent)
+    content = get_parent(event.object, IParagraphContainerTarget)
     if content is not None:
         get_current_registry().notify(ObjectModifiedEvent(content))