Ejemplo n.º 1
0
    def _new_state(self, request, **initial_state):
        task_id = re.sub('-', '', str(uuid.uuid4()))
        bind_to = binder(request)
        if bind_to is None:
            raise ImproperlyConfigured('A value is required to bind the task to')

        state = {'_id': task_id, '_bound_to': bind_to}
        state.update( initial_state )
        self.state_store.put_state(task_id, state)

        return state
Ejemplo n.º 2
0
    def _new_state(self, request, **initial_state):
        task_id = re.sub('-', '', str(uuid.uuid4()))
        bind_to = binder(request)
        if bind_to is None:
            raise ImproperlyConfigured(
                'A value is required to bind the task to')

        state = {'_id': task_id, '_bound_to': bind_to}
        state.update(initial_state)
        self.state_store.put_state(task_id, state)

        return state
Ejemplo n.º 3
0
        def handle_view(request, *args, **kwargs):
            # first get the state for this task, or create state if
            # this is an entry point with no state
            if config.FLOWS_TASK_ID_PARAM in request.REQUEST:
                task_id = request.REQUEST[config.FLOWS_TASK_ID_PARAM]

                try:
                    state = self._get_state(task_id)
                except StateNotFound:
                    logger.debug("Could not find task with ID %s" % task_id)
                    raise Http404

                bound_to = state.get('_bound_to', None)
                bind_to = binder(request)

                if bound_to is None or bind_to is None or bind_to != bound_to:
                    logger.debug(
                        'Will not give task %s as it is bound to %s, not %s' %
                        (task_id, bound_to, bind_to))
                    raise Http404

            else:
                # are we at an entry point? if so, then create some new state
                # otherwise we're trying to enter the middle of a flow, which
                # is not allowed
                if position.is_entry_point():
                    initial = {}
                    if '_on_complete' in request.REQUEST:
                        initial['_on_complete'] = request.REQUEST[
                            '_on_complete']
                    state = self._new_state(request, **initial)
                else:
                    logger.debug('Flow position is not an entry point: %s' %
                                 position)
                    raise Http404

            # create the instances required to handle the request
            flow_instance = position.create_instance(state, self.state_store,
                                                     args, kwargs)

            # deal with the request
            return flow_instance.handle(request, *args, **kwargs)
Ejemplo n.º 4
0
        def handle_view(request, *args, **kwargs):
            # first get the state for this task, or create state if
            # this is an entry point with no state
            if config.FLOWS_TASK_ID_PARAM in request.REQUEST:
                task_id = request.REQUEST[config.FLOWS_TASK_ID_PARAM]

                try:
                    state = self._get_state(task_id)
                except StateNotFound:
                    logger.debug("Could not find task with ID %s" % task_id)
                    raise Http404

                bound_to = state.get('_bound_to', None)
                bind_to = binder(request)

                if bound_to is None or bind_to is None or bind_to != bound_to:
                    logger.debug('Will not give task %s as it is bound to %s, not %s' % (task_id, bound_to, bind_to))
                    raise Http404

            else:
                # are we at an entry point? if so, then create some new state
                # otherwise we're trying to enter the middle of a flow, which
                # is not allowed
                if position.is_entry_point():
                    initial = {}
                    if '_on_complete' in request.REQUEST:
                        initial['_on_complete'] = request.REQUEST['_on_complete']
                    state = self._new_state(request, **initial)
                else:
                    logger.debug('Flow position is not an entry point: %s' % position)
                    raise Http404

            # create the instances required to handle the request
            flow_instance = position.create_instance(state, self.state_store, args, kwargs)

            # deal with the request
            return flow_instance.handle(request, *args, **kwargs)