Added ObjectClonedEvent
authorThierry Florac <thierry.florac@onf.fr>
Wed, 18 Mar 2015 10:07:51 +0100
changeset 2 6acf23529fc2
parent 1 a222398c5920
child 3 709aec888463
Added ObjectClonedEvent
src/pyams_workflow/content.py
src/pyams_workflow/interfaces/__init__.py
--- a/src/pyams_workflow/content.py	Tue Mar 17 16:18:00 2015 +0100
+++ b/src/pyams_workflow/content.py	Wed Mar 18 10:07:51 2015 +0100
@@ -19,7 +19,7 @@
 # import interfaces
 from pyams_security.interfaces import IPrincipalInfo
 from pyams_workflow.interfaces import IWorkflowManagedContent, IWorkflowPublicationInfo, IWorkflow, IWorkflowVersions, \
-    IWorkflowPublicationSupport
+    IWorkflowPublicationSupport, IObjectClonedEvent
 from zope.annotation.interfaces import IAnnotations
 
 # import packages
@@ -29,6 +29,7 @@
 from pyams_utils.request import check_request
 from pyams_utils.timezone import gmtime
 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
@@ -157,3 +158,9 @@
         registry.notify(ObjectCreatedEvent(info))
         locate(info, context)
     return info
+
+
+@subscriber(IObjectClonedEvent, context_selector=IWorkflowPublicationSupport)
+def handle_cloned_publication_support(event):
+    """Reset publication info when an object is cloned"""
+    IWorkflowPublicationInfo(event.object).reset()
--- a/src/pyams_workflow/interfaces/__init__.py	Tue Mar 17 16:18:00 2015 +0100
+++ b/src/pyams_workflow/interfaces/__init__.py	Wed Mar 18 10:07:51 2015 +0100
@@ -9,6 +9,8 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from zope.lifecycleevent import ObjectCreatedEvent
+from zope.lifecycleevent.interfaces import IObjectCreatedEvent
 
 __docformat__ = 'restructuredtext'
 
@@ -111,6 +113,21 @@
         self.old_object = old_object
 
 
+class IObjectClonedEvent(IObjectCreatedEvent):
+    """Object cloned event interface"""
+
+    source = Attribute("Cloned object source")
+
+
+@implementer(IObjectClonedEvent)
+class ObjectClonedEvent(ObjectCreatedEvent):
+    """Object cloned event"""
+
+    def __init__(self, object, source):
+        super(ObjectClonedEvent, self).__init__(object)
+        self.source = source
+
+
 class IWorkflow(Interface):
     """Defines workflow in the form of transition objects.