Back to index

plone3  3.1.7
delete.py
Go to the documentation of this file.
00001 from OFS.SimpleItem import SimpleItem
00002 from persistent import Persistent 
00003 
00004 from zope.interface import implements, Interface
00005 from zope.component import adapts
00006 from zope.formlib import form
00007 from zope import schema
00008 
00009 from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData
00010 
00011 from plone.app.contentrules.browser.formhelper import NullAddForm
00012 
00013 import transaction
00014 from Acquisition import aq_inner, aq_parent
00015 from ZODB.POSException import ConflictError
00016 from Products.CMFPlone import PloneMessageFactory as _
00017 
00018 from Products.CMFPlone import utils
00019 from Products.statusmessages.interfaces import IStatusMessage
00020 
00021 class IDeleteAction(Interface):
00022     """Interface for the configurable aspects of a delete action.
00023     """
00024              
00025 class DeleteAction(SimpleItem):
00026     """The actual persistent implementation of the action element.
00027     """
00028     implements(IDeleteAction, IRuleElementData)
00029     
00030     element = 'plone.actions.Delete'
00031     summary = _(u"Delete object")
00032     
00033 class DeleteActionExecutor(object):
00034     """The executor for this action.
00035     """
00036     implements(IExecutable)
00037     adapts(Interface, IDeleteAction, Interface)
00038          
00039     def __init__(self, context, element, event):
00040         self.context = context
00041         self.element = element
00042         self.event = event
00043 
00044     def __call__(self):
00045         obj = self.event.object
00046         parent = aq_parent(aq_inner(obj))
00047         
00048         transaction.savepoint()        
00049         
00050         try:
00051             parent.manage_delObjects(obj.getId())
00052         except ConflictError, e:
00053             raise e
00054         except Exception, e:
00055             self.error(obj, str(e))
00056             return False
00057         
00058         return True 
00059 
00060     def error(self, obj, error):
00061         request = getattr(self.context, 'REQUEST', None)
00062         if request is not None:
00063             title = utils.pretty_title_or_id(obj, obj)
00064             message = _(u"Unable to move ${name} as part of content rule 'move' action: ${error}",
00065                           mapping={'name' : title, 'error' : error})
00066             IStatusMessage(request).addStatusMessage(message, type="error")
00067         
00068 class DeleteAddForm(NullAddForm):
00069     """A degenerate "add form"" for delete actions.
00070     """
00071     
00072     def create(self):
00073         return DeleteAction()