Ejemplo n.º 1
0
def _do_auto_transition(context: IResource, registry: Registry):
    workflow = registry.content.get_workflow(context)
    next_states = workflow.get_next_states(context,
                                           create_fake_god_request(registry))
    print('Auto-transition of {} workflow to state {}.'
          .format(context, next_states))
    transition_to_states(context, next_states, registry)
Ejemplo n.º 2
0
def import_resources(root: IResource, registry: Registry, filename: str):
    """Import resources from a JSON file with dummy `god` user."""
    request = create_fake_god_request(registry)
    resources_info = _load_info(filename)
    for resource_info in resources_info:
        expected_path = _get_expected_path(resource_info)
        if _resource_exists(expected_path, root):
            logger.info('Skipping {}'.format(expected_path))
        else:
            logger.info('Creating {}'.format(expected_path))
            _create_resource(freeze(resource_info), request, registry, root)
Ejemplo n.º 3
0
def import_resources(root: IResource, registry: Registry, filename: str):
    """Import resources from a JSON file with dummy `god` user."""
    request = create_fake_god_request(registry)
    resources_info = _load_info(filename)
    for resource_info in resources_info:
        expected_path = _get_expected_path(resource_info)
        if _resource_exists(expected_path, root):
            logger.info('Skipping {}'.format(expected_path))
        else:
            logger.info('Creating {}'.format(expected_path))
            _create_resource(freeze(resource_info), request, registry, root)
Ejemplo n.º 4
0
def _state_is_outdated(context: IResource, registry: Registry,
                       date_now: datetime) -> bool:
    workflow = registry.content.get_workflow(context)
    next_states = workflow.get_next_states(context,
                                           create_fake_god_request(registry))
    if len(next_states) == 1:
        next_state = next_states[0]
        start_date_next = _get_next_state_start_date(context, registry,
                                                     next_state)
        if start_date_next:
            return date_now > start_date_next
    return False
Ejemplo n.º 5
0
def _print_workflow_info(root: IResource, registry: Registry,
                         resource_path: str):
    resource = find_resource(root, resource_path)
    workflow = registry.content.get_workflow(resource)
    states = set(
        registry.content.workflows_meta[workflow.type]['states'].keys())
    print('\nname: {}\ncurrent state: {}\nnext states: {}'
          '\nall states (unordered): {}\n'.format(
              workflow.type, workflow.state_of(resource),
              workflow.get_next_states(resource,
                                       create_fake_god_request(registry)),
              states))
Ejemplo n.º 6
0
def _print_workflow_info(root: IResource, registry: Registry, resource_path: str):
    resource = find_resource(root, resource_path)
    workflow = registry.content.get_workflow(resource)
    states = set(registry.content.workflows_meta[workflow.type]["states"].keys())
    print(
        "\nname: {}\ncurrent state: {}\nnext states: {}"
        "\nall states (unordered): {}\n".format(
            workflow.type,
            workflow.state_of(resource),
            workflow.get_next_states(resource, create_fake_god_request(registry)),
            states,
        )
    )
Ejemplo n.º 7
0
def transition_to_states(context, states: [str], registry: Registry,
                         reset=False):
    """Initialize workflow if needed and do transitions to the given states.

    :raises substanced.workflow.WorkflowError: if transition is missing to
        do transitions to `states`.
    """
    request = create_fake_god_request(registry)
    workflow = registry.content.get_workflow(context)
    # TODO: raise if workflow is None
    if not workflow.has_state(context) or reset:
        workflow.initialize(context)
    for state in states:
        workflow.transition_to_state(context, request, state)
Ejemplo n.º 8
0
def transition_to_states(context,
                         states: [str],
                         registry: Registry,
                         reset=False):
    """Initialize workflow if needed and do transitions to the given states.

    :raises substanced.workflow.WorkflowError: if transition is missing to
        do transitions to `states`.
    """
    request = create_fake_god_request(registry)
    workflow = registry.content.get_workflow(context)
    # TODO: raise if workflow is None
    if not workflow.has_state(context) or reset:
        workflow.initialize(context)
    for state in states:
        workflow.transition_to_state(context, request, state)