--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/paragraph/__init__.py Thu Oct 08 13:37:29 2015 +0200
@@ -0,0 +1,74 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.component.paragraph.interfaces import IBaseParagraph, IHTMLParagraph
+from pyams_content.shared.common.interfaces import IWfSharedContent
+from pyams_form.interfaces.form import IFormContextPermissionChecker
+from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
+
+# import packages
+from persistent import Persistent
+from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.traversing import get_parent
+from pyramid.events import subscriber
+from pyramid.threadlocal import get_current_registry
+from zope.container.contained import Contained
+from zope.interface import implementer
+from zope.lifecycleevent import ObjectModifiedEvent
+from zope.schema.fieldproperty import FieldProperty
+
+
+@implementer(IBaseParagraph)
+class BaseParagraph(Persistent, Contained):
+ """Base paragraph persistent class"""
+
+ title = FieldProperty(IBaseParagraph['title'])
+
+
+@adapter_config(context=IBaseParagraph, provides=IFormContextPermissionChecker)
+class BaseParagraphPermissionChecker(ContextAdapter):
+ """Paragraph permission checker"""
+
+ @property
+ def edit_permission(self):
+ content = get_parent(self.context, IWfSharedContent)
+ return IFormContextPermissionChecker(content).edit_permission
+
+
+@subscriber(IObjectAddedEvent, context_selector=IBaseParagraph)
+def handle_added_paragraph(event):
+ """Handle added paragraph"""
+ content = get_parent(event.object, IWfSharedContent)
+ if content is not None:
+ get_current_registry().notify(ObjectModifiedEvent(content))
+
+
+@subscriber(IObjectModifiedEvent, context_selector=IBaseParagraph)
+def handle_modified_paragraph(event):
+ """Handle modified paragraph"""
+ content = get_parent(event.object, IWfSharedContent)
+ if content is not None:
+ get_current_registry().notify(ObjectModifiedEvent(content))
+
+
+@subscriber(IObjectRemovedEvent, context_selector=IBaseParagraph)
+def handle_removed_paragraph(event):
+ """Handle removed paragraph"""
+ content = get_parent(event.object, IWfSharedContent)
+ if content is not None:
+ get_current_registry().notify(ObjectModifiedEvent(content))