parameters: (self, instance, *args, **kw)
return_statement: return result
docstring: Invoke the wrapped method, and deal with the results.
docstring_summary: Invoke the wrapped method, and deal with the results.
docstring_tokens: Invoke the wrapped method and deal with the results .
function: def __call__(self, instance, *args, **kw):
      """
        Invoke the wrapped method, and deal with the results.
      """
      try:
        wf = getattr(instance.getPortalObject(), 'portal_workflow')
      except AttributeError:
        # XXX instance is unwrapped(no acquisition)
        # XXX I must think that what is a correct behavior.(Yusei)
        return self.__dict__['_m'](instance, *args, **kw)
  
      # Build a list of transitions which may need to be invoked
      instance_path = instance.getPhysicalPath()
      portal_type = instance.portal_type
      transactional_variable = getTransactionalVariable()
      invoke_once_dict = self._invoke_once.get(portal_type, {})
      valid_invoke_once_item_list = []
      # Only keep those transitions which were never invoked
      once_transition_dict = {}
      for wf_id, transition_list in invoke_once_dict.iteritems():
        valid_transition_list = []
        for transition_id in transition_list:
          once_transition_key = ('Products.ERP5Type.Base.WorkflowMethod.__call__',
                                  wf_id, transition_id, instance_path)
          once_transition_dict[(wf_id, transition_id)] = once_transition_key
          if once_transition_key not in transactional_variable:
            valid_transition_list.append(transition_id)
        if valid_transition_list:
          valid_invoke_once_item_list.append((wf_id, valid_transition_list))
      candidate_transition_item_list = valid_invoke_once_item_list + \
                             self._invoke_always.get(portal_type, {}).items()
  
      #LOG('candidate_transition_item_list %s' % self.__name__, 0, str(candidate_transition_item_list))
  
      # Try to return immediately if there are no transition to invoke
      if not candidate_transition_item_list:
        return self.__dict__['_m'](instance, *args, **kw)
  
      # Prepare a list of transitions which should be invoked.
      # This list is based on the results of isWorkflowMethodSupported.
      # An interaction is ignored if the guard prevents execution.
      # Otherwise, an exception is raised if the workflow transition does not
      # exist from the current state, or if the guard rejects it.
      valid_transition_item_list = []
      for wf_id, transition_list in candidate_transition_item_list:
        candidate_workflow = wf[wf_id]
        valid_list = []
        state = candidate_workflow._getWorkflowStateOf(instance, id_only=0)
        for transition_id in transition_list:
          # cannot pass state parameter to an interaction workflow's
          # isWorkflowMethodSupported method
          is_supported_kw = {} if state is None else {'state': state}
  
          is_workflow_method_supported = candidate_workflow.isWorkflowMethodSupported(instance, transition_id, **is_supported_kw)
          if is_workflow_method_supported:
            valid_list.append(transition_id)
            once_transition_key = once_transition_dict.get((wf_id, transition_id))
            if once_transition_key:
              # a run-once transition, prevent it from running again in
              # the same transaction
              transactional_variable[once_transition_key] = 1
          elif candidate_workflow.__class__.__name__ in ['DCWorkflowDefinition', 'Workflow']:
            raise UnsupportedWorkflowMethod(instance, wf_id, transition_id)
            # XXX Keep the log for projects that needs to comment out
            #     the previous line.
            LOG("WorkflowMethod.__call__", ERROR,
                "Transition %s/%s on %r is ignored. Current state is %r."
                % (wf_id, transition_id, instance, state))
        if valid_list:
          valid_transition_item_list.append((wf_id, valid_list))
  
      #LOG('valid_transition_item_list %s' % self.__name__, 0, str(valid_transition_item_list))
  
      # Call whatever must be called before changing states
      for wf_id, transition_list in valid_transition_item_list:
         wf[wf_id].notifyBefore(instance, transition_list, args=args, kw=kw)
  
      # Compute expected result
      result = self.__dict__['_m'](instance, *args, **kw)
  
      # Change the state of statefull workflows
      for wf_id, transition_list in valid_transition_item_list:
        try:
          wf[wf_id].notifyWorkflowMethod(instance, transition_list, args=args, kw=kw)
        except ObjectDeleted:
          # Re-raise with a different result.
          raise ObjectDeleted(result)
        except ObjectMoved, ex:
          # Re-raise with a different result.
          raise ObjectMoved(ex.getNewObject(), result)
  
      # Call whatever must be called after changing states
      for wf_id, transition_list in valid_transition_item_list:
        wf[wf_id].notifySuccess(instance, transition_list, result, args=args, kw=kw)
  
      # Return result finally
      return result
function_tokens: def __call__ ( self , instance , * args , * * kw ) : try : wf = getattr ( instance . getPortalObject ( ) , 'portal_workflow' ) except AttributeError : # XXX instance is unwrapped(no acquisition) # XXX I must think that what is a correct behavior.(Yusei) return self . __dict__ [ '_m' ] ( instance , * args , * * kw ) # Build a list of transitions which may need to be invoked instance_path = instance . getPhysicalPath ( ) portal_type = instance . portal_type transactional_variable = getTransactionalVariable ( ) invoke_once_dict = self . _invoke_once . get ( portal_type , { } ) valid_invoke_once_item_list = [ ] # Only keep those transitions which were never invoked once_transition_dict = { } for wf_id , transition_list in invoke_once_dict . iteritems ( ) : valid_transition_list = [ ] for transition_id in transition_list : once_transition_key = ( 'Products.ERP5Type.Base.WorkflowMethod.__call__' , wf_id , transition_id , instance_path ) once_transition_dict [ ( wf_id , transition_id ) ] = once_transition_key if once_transition_key not in transactional_variable : valid_transition_list . append ( transition_id ) if valid_transition_list : valid_invoke_once_item_list . append ( ( wf_id , valid_transition_list ) ) candidate_transition_item_list = valid_invoke_once_item_list + self . _invoke_always . get ( portal_type , { } ) . items ( ) #LOG('candidate_transition_item_list %s' % self.__name__, 0, str(candidate_transition_item_list)) # Try to return immediately if there are no transition to invoke if not candidate_transition_item_list : return self . __dict__ [ '_m' ] ( instance , * args , * * kw ) # Prepare a list of transitions which should be invoked. # This list is based on the results of isWorkflowMethodSupported. # An interaction is ignored if the guard prevents execution. # Otherwise, an exception is raised if the workflow transition does not # exist from the current state, or if the guard rejects it. valid_transition_item_list = [ ] for wf_id , transition_list in candidate_transition_item_list : candidate_workflow = wf [ wf_id ] valid_list = [ ] state = candidate_workflow . _getWorkflowStateOf ( instance , id_only = 0 ) for transition_id in transition_list : # cannot pass state parameter to an interaction workflow's # isWorkflowMethodSupported method is_supported_kw = { } if state is None else { 'state' : state } is_workflow_method_supported = candidate_workflow . isWorkflowMethodSupported ( instance , transition_id , * * is_supported_kw ) if is_workflow_method_supported : valid_list . append ( transition_id ) once_transition_key = once_transition_dict . get ( ( wf_id , transition_id ) ) if once_transition_key : # a run-once transition, prevent it from running again in # the same transaction transactional_variable [ once_transition_key ] = 1 elif candidate_workflow . __class__ . __name__ in [ 'DCWorkflowDefinition' , 'Workflow' ] : raise UnsupportedWorkflowMethod ( instance , wf_id , transition_id ) # XXX Keep the log for projects that needs to comment out #     the previous line. LOG ( "WorkflowMethod.__call__" , ERROR , "Transition %s/%s on %r is ignored. Current state is %r." % ( wf_id , transition_id , instance , state ) ) if valid_list : valid_transition_item_list . append ( ( wf_id , valid_list ) ) #LOG('valid_transition_item_list %s' % self.__name__, 0, str(valid_transition_item_list)) # Call whatever must be called before changing states for wf_id , transition_list in valid_transition_item_list : wf [ wf_id ] . notifyBefore ( instance , transition_list , args = args , kw = kw ) # Compute expected result result = self . __dict__ [ '_m' ] ( instance , * args , * * kw ) # Change the state of statefull workflows for wf_id , transition_list in valid_transition_item_list : try : wf [ wf_id ] . notifyWorkflowMethod ( instance , transition_list , args = args , kw = kw ) except ObjectDeleted : # Re-raise with a different result. raise ObjectDeleted ( result ) except ObjectMoved , ex : # Re-raise with a different result. raise ObjectMoved ( ex . getNewObject ( ) , result ) # Call whatever must be called after changing states for wf_id , transition_list in valid_transition_item_list : wf [ wf_id ] . notifySuccess ( instance , transition_list , result , args = args , kw = kw ) # Return result finally return result