# HG changeset patch # User Thierry Florac # Date 1426669671 -3600 # Node ID 6acf23529fc2e84d4969fea5d00bf5937b71b87c # Parent a222398c5920fe870145ed92f058b6f83b270508 Added ObjectClonedEvent diff -r a222398c5920 -r 6acf23529fc2 src/pyams_workflow/content.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() diff -r a222398c5920 -r 6acf23529fc2 src/pyams_workflow/interfaces/__init__.py --- 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.