def before_file_remove(obj, event): request = getattr(obj, 'REQUEST', '') if request and hasattr(request, 'ACTUAL_URL') and \ request.ACTUAL_URL.endswith('delete_confirmation') and \ request.get('REQUEST_METHOD') == 'GET': # delete event is fired by link integrity check, skip it. return # skip source remove if we have appropriate flag set in request annotations = IAnnotations(request) if annotations and annotations.has_key(SKIP_SOURCE_REMOVE_FLAG) and \ annotations[SKIP_SOURCE_REMOVE_FLAG]: return try: remove_source(obj) except AWSSourceRemoveError, e: IStatusMessage(request).addStatusMessage(_(e), type='error') utils.abort_transaction(request)
def before_file_remove(obj, event): request = getattr(obj, "REQUEST", "") if ( request and hasattr(request, "ACTUAL_URL") and request.ACTUAL_URL.endswith("delete_confirmation") and request.get("REQUEST_METHOD") == "GET" ): # delete event is fired by link integrity check, skip it. return # skip source remove if we have appropriate flag set in request annotations = IAnnotations(request) if annotations and SKIP_SOURCE_REMOVE_FLAG in annotations and annotations[SKIP_SOURCE_REMOVE_FLAG]: return try: remove_source(obj) except AWSSourceRemoveError, e: IStatusMessage(request).addStatusMessage(_(e), type="error") utils.abort_transaction(request)
def object_cloned(obj, event): def cleanup(obj): catalog = getToolByName(obj, "portal_catalog") container = aq_parent(aq_inner(obj)) # we have to skip source remove to be able to remove object. utils.skip_source_remove(obj.REQUEST) catalog.uncatalog_object("/".join(obj.getPhysicalPath())) for brain in catalog(path={"depth": 1, "query": "/".join(obj.getPhysicalPath())}): catalog.uncatalog_object(brain.getPath()) container.manage_delObjects(ids=[obj.getId()]) request = obj.REQUEST try: clone_source(obj) except AWSSourceCopyError, e: cleanup(obj) if aq_parent(aq_inner(obj)) is event.object: # clean up parent object cleanup(event.object) IStatusMessage(request).addStatusMessage(_(e), type="error") request.RESPONSE.redirect(request.get("HTTP_REFERER"))