Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
plone.app.contentrules.actions.move.MoveActionExecutor Class Reference

List of all members.

Public Member Functions

def __init__
def __call__
def error
def generate_id

Public Attributes

 context
 element
 event

Detailed Description

The executor for this action.

Definition at line 56 of file move.py.


Constructor & Destructor Documentation

def plone.app.contentrules.actions.move.MoveActionExecutor.__init__ (   self,
  context,
  element,
  event 
)

Definition at line 62 of file move.py.

00062 
00063     def __init__(self, context, element, event):
00064         self.context = context
00065         self.element = element
00066         self.event = event

Here is the caller graph for this function:


Member Function Documentation

Definition at line 67 of file move.py.

00067 
00068     def __call__(self):
00069         portal_url = getToolByName(self.context, 'portal_url', None)
00070         if portal_url is None:
00071             return False
00072         
00073         obj = self.event.object
00074         parent = aq_parent(aq_inner(obj))
00075         
00076         path = self.element.target_folder
00077         if len(path) > 1 and path[0] == '/':
00078             path = path[1:]
00079         target = portal_url.getPortalObject().unrestrictedTraverse(str(path), None)
00080     
00081         if target is None:
00082             self.error(obj, _(u"Target folder ${target} does not exist.", mapping={'target' : path}))
00083             return False
00084             
00085         if target.absolute_url() == parent.absolute_url():
00086             # We're already here!
00087             return True
00088         
00089         try:
00090             obj._notifyOfCopyTo(target, op=1)
00091         except ConflictError:
00092             raise
00093         except Exception, e:
00094             self.error(obj, str(e))
00095             return False
00096 
00097         # Are we trying to move into the same container that we copied from?
00098         if not sanity_check(target, obj):
00099             return False
00100 
00101         old_id = obj.getId()
00102         new_id = self.generate_id(target, old_id)
00103 
00104         notify(ObjectWillBeMovedEvent(obj, parent, old_id, target, new_id))
00105 
00106         obj.manage_changeOwnershipType(explicit=1)
00107 
00108         try:
00109             parent._delObject(old_id, suppress_events=True)
00110         except TypeError:
00111             # BBB: removed in Zope 2.11
00112             parent._delObject(old_id)
00113         
00114         obj = aq_base(obj)
00115         obj._setId(new_id)
00116 
00117         try:
00118             target._setObject(new_id, obj, set_owner=0, suppress_events=True)
00119         except TypeError:
00120             # BBB: removed in Zope 2.11
00121             target._setObject(new_id, obj, set_owner=0)
00122         obj = target._getOb(new_id)
00123 
00124         notify(ObjectMovedEvent(obj, parent, old_id, target, new_id))
00125         notifyContainerModified(parent)
00126         if aq_base(parent) is not aq_base(target):
00127             notifyContainerModified(target)
00128 
00129         obj._postCopy(target, op=1)
00130         
00131         # try to make ownership implicit if possible
00132         obj.manage_changeOwnershipType(explicit=0)
00133         
00134         return True
        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 135 of file move.py.

00135 
00136     def error(self, obj, error):
00137         request = getattr(self.context, 'REQUEST', None)
00138         if request is not None:
00139             title = utils.pretty_title_or_id(obj, obj)
00140             message = _(u"Unable to move ${name} as part of content rule 'move' action: ${error}",
00141                           mapping={'name' : title, 'error' : error})
00142             IStatusMessage(request).addStatusMessage(message, type="error")
            

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 143 of file move.py.

00143 
00144     def generate_id(self, target, old_id):
00145         taken = getattr(target, 'has_key', None)
00146         if taken is None:
00147             item_ids = set(target.objectIds())
00148             taken = lambda x: x in item_ids
00149         if not taken(old_id):
00150             return old_id
00151         idx = 1
00152         while taken("%s.%d" % (old_id, idx)):
00153             idx += 1
00154         return "%s.%d" % (old_id, idx)
        

Here is the caller graph for this function:


Member Data Documentation

Definition at line 63 of file move.py.

Definition at line 64 of file move.py.

Definition at line 65 of file move.py.


The documentation for this class was generated from the following file: