function get_next_status_v1
Returns the next status in a predefined workflow state machine, progressing from DRAFT through to OBSOLETE.
/tf/active/vicechatdev/CDocs single class/config/settings.py
344 - 361
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', ...}
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_next_status 81.5% similar
-
function get_status_after_approval 71.2% similar
-
function is_valid_status_transition 65.1% similar
-
function get_version 64.9% similar
-
class WorkflowStatus 64.5% similar