def publish_after_transition(obj, event):
    """ This event handler is executed after each transition and
    publishes the object with ftw.publisher on certain transitions.

    Also when retracting an object, the object will be published,
    since we should not delete anything unless it's delete from the
    sender instance too. This is necessary for preventing
    inconsistency, which could occur when deleting a folder which
    contains published objects on the reciever site.
    """

    # the event handler will be run multiple times, so we need to
    # remember which event we've already handled.
    if getattr(event, _marker, False):
        return
    else:
        setattr(event, _marker, True)

    # when there is no transition for the state change, we do nothing
    if not event.transition:
        return

    # do nothing with temprorary objects
    if is_temporary(obj):
        return

    # check if we should handle this transaction
    wf_transition = (event.workflow.__name__, event.transition.__name__)
    if wf_transition in config.PUSH_TRANSITIONS:
        action = 'push'
    elif wf_transition in config.DELETE_TRANSITIONS:
        action = 'delete'
    else:
        return

    if is_action_possible(obj, action):
        if action == 'push':
            obj.restrictedTraverse('publisher.publish')()
        elif action == 'delete':
            obj.restrictedTraverse('publisher.delete')()
예제 #2
0
def publish_after_transition(obj, event):
    """ This event handler is executed after each transition and
    publishes the object with ftw.publisher on certain transitions.

    Also when retracting an object, the object will be published,
    since we should not delete anything unless it's delete from the
    sender instance too. This is necessary for preventing
    inconsistency, which could occur when deleting a folder which
    contains published objects on the reciever site.
    """

    # the event handler will be run multiple times, so we need to
    # remember which event we've already handled.
    if getattr(event, _marker, False):
        return
    else:
        setattr(event, _marker, True)

    # when there is no transition for the state change, we do nothing
    if not event.transition:
        return

    # do nothing with temprorary objects
    if is_temporary(obj):
        return

    # check if we should handle this transaction
    wf_transition = (event.workflow.__name__, event.transition.__name__)
    if wf_transition in config.PUSH_TRANSITIONS:
        action = 'push'
    elif wf_transition in config.DELETE_TRANSITIONS:
        action = 'delete'
    else:
        return

    if is_action_possible(obj, action):
        if action == 'push':
            obj.restrictedTraverse('publisher.publish')()
        elif action == 'delete':
            obj.restrictedTraverse('publisher.delete')()
예제 #3
0
 def check_submit_allowed(self, state_change):
     if not is_action_possible(self.context, 'submit',
                               show_warnings=True, show_errors=True):
         raise Redirect(self.request.get('HTTP_REFERER'))
     else:
         return state_change