# HG changeset patch # User Thierry Florac # Date 1432118689 -7200 # Node ID 6f4862c4801993d5e258b1dfa7c353e3f0687851 # Parent 43c135a76ab2fb081bcfbd7a1baa52cb81574190 Added subscriber for cloned object event diff -r 43c135a76ab2 -r 6f4862c48019 src/pyams_workflow/content.py --- a/src/pyams_workflow/content.py Wed May 20 12:44:10 2015 +0200 +++ b/src/pyams_workflow/content.py Wed May 20 12:44:49 2015 +0200 @@ -19,7 +19,7 @@ # import interfaces from pyams_security.interfaces import IPrincipalInfo from pyams_workflow.interfaces import IWorkflowManagedContent, IWorkflowPublicationInfo, IWorkflow, IWorkflowVersions, \ - IWorkflowPublicationSupport, IObjectClonedEvent + IWorkflowPublicationSupport, IObjectClonedEvent, IWorkflowState 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 pyams_workflow.versions import WorkflowHistoryItem from pyramid.events import subscriber from pyramid.threadlocal import get_current_registry from zope.container.contained import Contained @@ -37,6 +38,8 @@ from zope.location import locate from zope.schema.fieldproperty import FieldProperty +from pyams_workflow import _ + @implementer(IWorkflowPublicationInfo) class WorkflowContentPublicationInfo(Persistent, Contained): @@ -160,6 +163,21 @@ return info +@subscriber(IObjectClonedEvent) +def handle_cloned_object(event): + """Add comment when an object is cloned""" + request = check_request() + translate = request.localizer.translate + source_state = IWorkflowState(event.source) + target_state = IWorkflowState(event.object) + item = WorkflowHistoryItem(date=datetime.utcnow(), + source_state=source_state.state, + principal=request.principal.id, + comment=translate(_("Clone created from version {source}")).format( + source=source_state.version_id)) + target_state.history.append(item) + + @subscriber(IObjectClonedEvent, context_selector=IWorkflowPublicationSupport) def handle_cloned_publication_support(event): """Reset publication info when an object is cloned"""