def haunt_created_folder(folder, event): if (folder != event.object or IObjectCopiedEvent.providedBy(event)): return # If the ghost folder is in a valid state after creation or copy, # haunt its content. if folder.get_link_status() is None: folder.haunt()
def content_created(content, event): if (content != event.object or IObjectCopiedEvent.providedBy(event) or IVersionedContent.providedBy(content)): return ICataloging(content).index() ChangesTask.get().modified(content, created=True)
def extract_what(self): #Archetypes if IObjectInitializedEvent.providedBy(self.event): return 'created', self.get_object_modified_info() elif IObjectEditedEvent.providedBy(self.event): return 'modified', self.get_object_modified_info() # #TODO: plone.app.iterate # elif ICheckinEvent.providedBy(self.event): # return 'checkedin' # elif ICheckoutEvent.providedBy(self.event): # return 'checkedout' # elif IWorkingCopyDeletedEvent.providedBy(self.event): # return 'workingcopydeleted' # DCWorkflow elif IAfterTransitionEvent.providedBy(self.event): return 'statechanged', self.get_transition_info() # CMFCore (useless) # elif IActionSucceededEvent.providedBy(self.event): # return None # return 'statechanged', self.get_action_succeed_info() # zope # elif IObjectAddedEvent.providedBy(self.event): # return 'added', self.get_object_moved_info() elif IObjectCopiedEvent.providedBy(self.event): return 'copied', self.get_object_copied_info() elif IObjectMovedEvent.providedBy(self.event): return 'moved', self.get_object_moved_info() elif IObjectRemovedEvent.providedBy(self.event): return 'removed', self.get_object_moved_info() elif IObjectModifiedEvent.providedBy(self.event): return 'modified', self.get_object_modified_info() return None, {}
def version_created(version, event): if IObjectCopiedEvent.providedBy(event): return created = version == event.object ChangesTask.get().modified(version, created) if created: ICataloging(version).index() ICataloging(version.get_silva_object()).index(with_versions=False)
def initialize_metadata(mail, event): if not ogmetadata.IDocumentMetadata.providedBy(mail): return if IObjectCopiedEvent.providedBy(event): return mail_metadata = ogmetadata.IDocumentMetadata(mail) date_time = datetime.fromtimestamp(utils.get_date_header(mail.msg, 'Date')) mail_metadata.document_date = date_time.date() mail_metadata.receipt_date = date.today() mail_metadata.document_author = get_author_by_email(mail)
def addAttributeUUID(obj, event): if not IObjectCopiedEvent.providedBy(event): if getattr(aq_base(obj), ATTRIBUTE_NAME, None): return # defensive: keep existing UUID on non-copy create generator = queryUtility(IUUIDGenerator) if generator is None: return uuid = generator() if not uuid: return setattr(obj, ATTRIBUTE_NAME, uuid)
def addAttributeTG(obj, event): if not IObjectCopiedEvent.providedBy(event): if getattr(aq_base(obj), ATTRIBUTE_NAME, None): return # defensive: keep existing TG on non-copy create generator = component.queryUtility(IUUIDGenerator) if generator is None: return tg = generator() if not tg: return setattr(obj, ATTRIBUTE_NAME, tg)
def testCopyEvents(self): cp = self.reflecto.manage_copyObjects(('foo',)) self.reflecto.manage_pasteObjects(cp) events = getEvents() self.assertEqual(len(events), 3) self.assertTrue(IObjectCopiedEvent.providedBy(events[0])) self.assertEqual(events[0].original.getId(), 'foo') self.assertEqual(events[0].object.getId(), 'copy_of_foo') self.assertTrue(IObjectClonedEvent.providedBy(events[1])) self.assertEqual(events[1].object.getId(), 'copy_of_foo') self.assertTrue(IContainerModifiedEvent.providedBy(events[2])) self.assertTrue(events[2].object is self.reflecto)
def testCopyEvents(self): cp = self.reflecto.manage_copyObjects(('foo', )) self.reflecto.manage_pasteObjects(cp) events = getEvents() self.assertEqual(len(events), 3) self.assertTrue(IObjectCopiedEvent.providedBy(events[0])) self.assertEqual(events[0].original.getId(), 'foo') self.assertEqual(events[0].object.getId(), 'copy_of_foo') self.assertTrue(IObjectClonedEvent.providedBy(events[1])) self.assertEqual(events[1].object.getId(), 'copy_of_foo') self.assertTrue(IContainerModifiedEvent.providedBy(events[2])) self.assertTrue(events[2].object is self.reflecto)
def addAttributeTG(obj, event): if ( not IObjectCopiedEvent.providedBy(event) and getattr(aq_base(obj), ATTRIBUTE_NAME, None) ): return # defensive: keep existing TG on non-copy create generator = queryUtility(IUUIDGenerator) if generator is None: return tg = generator() if not tg: return setattr(obj, ATTRIBUTE_NAME, tg)
def created_event(event): obj = event.object if is_portal_factory(obj): return if IObjectCopiedEvent.providedBy(event): return # ignore this event since we're listening to cloned instead # The object added event executes too early for Archetypes objects. # We need to delay execution until we receive a subsequent # IObjectInitializedEvent if IBaseObject.providedBy(obj): cr_handlers.init() cr_handlers._status.delayed_events[ 'IObjectInitializedEvent-audit-%s' % getUID(obj)] = event elif IContentish.providedBy(obj) or IComment.providedBy(obj): execute_event(event) else: return
def unrelateOnCopy(event): """Remove all relationships when an object is copied.""" if not IObjectCopiedEvent.providedBy(event): return # event.object may be a ContainedProxy obj = getProxiedObject(event.object) linkset = IRelationshipLinks(obj, None) if linkset is not None: links_to_remove = [] for link in linkset: other_linkset = IRelationshipLinks(link.target) try: other_linkset.find(link.role, obj, link.my_role, link.rel_type) except ValueError: # The corresponding other link was not copied, so we have a # degenerate one-sided relationship. Let's remove it # altogether. It would not difficult to have a different # function, cloneRelationshipsOnCopy, that would create # a corresponding link in other_linkset. links_to_remove.append(link) for link in links_to_remove: linkset.remove(link)
def update_todo_state(obj, event): """ After editing a Todo item, set the workflow state to either Open or Planned depending on the state of the Case. Also update access permissions on the Case, which might have changed due to a change in assignment. """ # Do nothing on copy if IObjectCopiedEvent.providedBy(event): return if IObjectAddedEvent.providedBy(event): # This attribute is set when copying from a template # handle_case_workflow_state_changed will take care of everything if getattr(event.newParent, '_v_skip_update_todo_state', None): return obj.set_appropriate_state() obj.reindexObject() parent = parent_workspace(obj) if ICase.providedBy(parent): parent.update_case_access()
def handleContentishEvent(ob, event): """ Event subscriber for (IContentish, IObjectEvent) events. """ if IObjectAddedEvent.providedBy(event): ob.notifyWorkflowCreated() ob.indexObject() elif IObjectMovedEvent.providedBy(event): if event.newParent is not None: ob.indexObject() elif IObjectWillBeMovedEvent.providedBy(event): if event.oldParent is not None: ob.unindexObject() elif IObjectCopiedEvent.providedBy(event): if hasattr(aq_base(ob), 'workflow_history'): del ob.workflow_history elif IObjectCreatedEvent.providedBy(event): if hasattr(aq_base(ob), 'addCreator'): ob.addCreator()
def get_what_info(self, event): #Archetypes if IObjectEditedEvent.providedBy(event): return self.get_object_modified_info(event) elif IObjectInitializedEvent.providedBy(event): return self.get_object_modified_info(event) #plone elif IConfigurationChangedEvent.providedBy(event): return self.get_configuration_changed_info(event) # #plone.app.form (formlib) # elif IEditSavedEvent.providedBy(event): # return 'editsaved' # #plone.app.iterate # elif ICheckinEvent.providedBy(event): # return 'checkedin' # elif ICheckoutEvent.providedBy(event): # return 'checkedout' # elif IWorkingCopyDeletedEvent.providedBy(event): # return 'workingcopydeleted' # #plone.app.registry elif IRecordModifiedEvent.providedBy(event): return self.get_record_modified_info(event) # DCWorkflow elif ITransitionEvent.providedBy(event): return self.get_transition_info(event) # CMFCore elif IActionSucceededEvent.providedBy(event): return self.get_action_succeed_info(event) # zope elif IObjectCopiedEvent.providedBy(event): return self.get_object_copied_info(event) elif IObjectMovedEvent.providedBy(event): return self.get_object_moved_info(event) elif IObjectAddedEvent.providedBy(event): return self.get_object_moved_info(event) elif IObjectRemovedEvent.providedBy(event): return self.get_object_moved_info(event)
def log_create(content, event): if IObjectCopiedEvent.providedBy(event): detail = 'from %s' % get_path(event.original) LoggingEvent('copy', content, detail).log() else: LoggingEvent('create', content).log()
def content_created(content, event): if content != event.object or IObjectCopiedEvent.providedBy(event) or IVersionedContent.providedBy(content): return ICataloging(content).index() ChangesTask.get().modified(content, created=True)
def markCreateEvent(obj, event): if IObjectCopiedEvent.providedBy(event): return context = api.portal.get() request = context.REQUEST request.set("creating", True)
def handleContentishEvent(ob, event): """ Event subscriber for (IContentish, IObjectEvent) events. """ if IObjectAddedEvent.providedBy(event): ob.notifyWorkflowCreated() ob.indexObject() elif IObjectMovedEvent.providedBy(event): if event.newParent is not None: if hasattr(aq_base(ob), 'notifyModified'): ob.notifyModified() rid = getattr(ob, '__rid', None) if rid: catalog = api.portal.get_tool('portal_catalog') _catalog = catalog._catalog new_path = '/'.join(ob.getPhysicalPath()) old_path = _catalog.paths[rid] del _catalog.uids[old_path] _catalog.uids[new_path] = rid _catalog.paths[rid] = new_path ob.reindexObject(idxs=[ 'path', 'allowedRolesAndUsers', 'modified', 'id', 'getId' ]) delattr(ob, '__rid') elif event.newParent is not None: # This may happen if "collective.indexing" is installed and an object # is added and renamed/moved in the same transaction (e.g. during the # creation of an object with "plone.api" in a subscriber listening # on "IObjectAddedEvent" as in https://github.com/4teamwork/ftw.events/blob/f1a77440866c6d963961497f68781098c1b4bc8f/ftw/events/configure.zcml#L22). ob.indexObject() elif IObjectWillBeMovedEvent.providedBy(event): from ftw.copymovepatches.utils import getQueue # Prepare Rename if indexing queue is implemented if event.oldParent == event.newParent and getQueue is not None: # The queue needs to be processed, since the `renameObjectsByPaths` # script allows the user to rename the object and also sets a new # title if he wants. # In some circumstances this leads to a inconsistent catalog state. # Mainly if other event handler also triggers a `process` queue by # asking the catalog for something. # The result was for example a "reindex" of a already deleted # object. queue = getQueue() queue.process() # Move/Rename if event.oldParent is not None and event.newParent is not None: catalog = api.portal.get_tool('portal_catalog') ob_path = '/'.join(ob.getPhysicalPath()) if ob_path in catalog._catalog.uids: rid = catalog._catalog.uids[ob_path] setattr(ob, '__rid', rid) else: # This may happen if "collective.indexing" is installed and an object # is added and renamed/moved in the same transaction (e.g. during the # creation of an object with "plone.api" in a subscriber listening # on "IObjectAddedEvent" as in https://github.com/4teamwork/ftw.events/blob/f1a77440866c6d963961497f68781098c1b4bc8f/ftw/events/configure.zcml#L22). return elif event.oldParent is not None: # Delete ob.unindexObject() elif IObjectCopiedEvent.providedBy(event): if hasattr(aq_base(ob), 'workflow_history'): del ob.workflow_history elif IObjectCreatedEvent.providedBy(event): if hasattr(aq_base(ob), 'addCreator'): ob.addCreator()