🔍 Code Extractor

function get_next_status_v1

Maturity: 46

Returns the next status in a predefined workflow state machine, progressing from DRAFT through to OBSOLETE.

File:
/tf/active/vicechatdev/CDocs single class/config/settings.py
Lines:
344 - 361
Complexity:
simple

Purpose

This function implements a linear workflow state transition system, commonly used in document management, content publishing, or approval processes. It takes a current status and returns the next logical status in the sequence: DRAFT → IN_REVIEW → IN_APPROVAL → APPROVED → PUBLISHED → EFFECTIVE → ARCHIVED → OBSOLETE. If an unknown status is provided, it returns the current status unchanged, preventing invalid state transitions.

Source Code

def get_next_status(current_status):
    """Get the next logical status in the workflow."""
    if current_status == 'DRAFT':
        return 'IN_REVIEW'
    elif current_status == 'IN_REVIEW':
        return 'IN_APPROVAL'
    elif current_status == 'IN_APPROVAL':
        return 'APPROVED'
    elif current_status == 'APPROVED':
        return 'PUBLISHED'
    elif current_status == 'PUBLISHED':
        return 'EFFECTIVE'
    elif current_status == 'EFFECTIVE':
        return 'ARCHIVED'
    elif current_status == 'ARCHIVED':
        return 'OBSOLETE'
    else:
        return current_status  # No change if unknown status

Parameters

Name Type Default Kind
current_status - - positional_or_keyword

Parameter Details

current_status: A string representing the current status in the workflow. Expected values are: 'DRAFT', 'IN_REVIEW', 'IN_APPROVAL', 'APPROVED', 'PUBLISHED', 'EFFECTIVE', 'ARCHIVED', or 'OBSOLETE'. The function is case-sensitive and expects uppercase status values. Any other value will be returned unchanged.

Return Value

Returns a string representing the next status in the workflow sequence. If the current_status is 'DRAFT', returns 'IN_REVIEW'; if 'IN_REVIEW', returns 'IN_APPROVAL', and so on. If current_status is 'OBSOLETE' (the final state) or an unrecognized value, returns the current_status unchanged. Return type is always a string.

Usage Example

# Basic usage
status = 'DRAFT'
next_status = get_next_status(status)
print(next_status)  # Output: 'IN_REVIEW'

# Progressing through workflow
current = 'DRAFT'
while current != 'OBSOLETE':
    next_state = get_next_status(current)
    print(f'{current} -> {next_state}')
    if next_state == current:  # No more transitions
        break
    current = next_state

# Handling unknown status
unknown = get_next_status('INVALID_STATUS')
print(unknown)  # Output: 'INVALID_STATUS'

# Final state handling
final = get_next_status('OBSOLETE')
print(final)  # Output: 'OBSOLETE'

Best Practices

  • Status values are case-sensitive; always use uppercase strings (e.g., 'DRAFT', not 'draft')
  • Consider using an Enum instead of strings for type safety and to prevent typos
  • The function does not validate if the current_status is a valid state; it simply returns it unchanged if unrecognized
  • This implements a linear workflow; for complex workflows with branching or backward transitions, consider a more sophisticated state machine
  • OBSOLETE is the terminal state; calling get_next_status on it returns OBSOLETE
  • Consider adding logging or raising exceptions for invalid status values in production code
  • For bidirectional workflows (allowing status rollback), implement a separate get_previous_status function
  • Consider refactoring to use a dictionary mapping for easier maintenance: STATUS_TRANSITIONS = {'DRAFT': 'IN_REVIEW', ...}

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_next_status 81.5% similar

    Determines the next logical status in a document lifecycle workflow based on the current status, using either configured transitions or a predefined fallback flow.

    From: /tf/active/vicechatdev/CDocs/models/document_status.py
  • function get_status_after_approval 71.2% similar

    Determines the next status for a controlled document based on an approval decision (APPROVED or REJECTED), transitioning documents through their lifecycle workflow.

    From: /tf/active/vicechatdev/CDocs/controllers/document_controller.py
  • function is_valid_status_transition 65.1% similar

    Validates whether a transition from one status to another is allowed based on predefined valid status transitions.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_version 64.9% similar

    Returns a list of valid status codes that a document can transition to from its current status, using either configured transitions from settings or predefined fallback rules.

    From: /tf/active/vicechatdev/CDocs/models/document_status.py
  • class WorkflowStatus 64.5% similar

    An enumeration class that defines the possible status values for workflow cycles, including both review and approval workflows.

    From: /tf/active/vicechatdev/CDocs single class/models/workflow_base.py
← Back to Browse