function get_next_status
Determines the next logical status in a document lifecycle workflow based on the current status, using either configured transitions or a predefined fallback flow.
/tf/active/vicechatdev/CDocs/models/document_status.py
61 - 95
simple
Purpose
This function manages document status progression through a lifecycle (draft → review → approval → published → effective → archived → obsolete). It first checks for custom status transitions defined in settings.VALID_STATUS_TRANSITIONS, and if not found, falls back to a hardcoded status flow. This allows for flexible workflow configuration while maintaining a sensible default progression.
Source Code
def get_next_status(current_status: str) -> str:
"""
Get the next logical status in the document lifecycle
Parameters
----------
current_status : str
Current document status
Returns
-------
str
Next logical status, or the same status if at the end of the lifecycle
"""
# Convert to uppercase for consistency with settings
upper_status = current_status.upper()
# Use the valid transitions from settings
if hasattr(settings, 'VALID_STATUS_TRANSITIONS') and upper_status in settings.VALID_STATUS_TRANSITIONS:
transitions = settings.VALID_STATUS_TRANSITIONS[upper_status]
return transitions[0] if transitions else upper_status
# Fallback to predefined flow
status_flow = {
STATUS_DRAFT: STATUS_IN_REVIEW,
STATUS_IN_REVIEW: STATUS_IN_APPROVAL,
STATUS_IN_APPROVAL: STATUS_APPROVED,
STATUS_APPROVED: STATUS_PUBLISHED,
STATUS_PUBLISHED: STATUS_EFFECTIVE,
STATUS_EFFECTIVE: STATUS_ARCHIVED,
STATUS_ARCHIVED: STATUS_OBSOLETE,
STATUS_OBSOLETE: STATUS_OBSOLETE # Terminal state
}
return status_flow.get(upper_status, upper_status)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
current_status |
str | - | positional_or_keyword |
Parameter Details
current_status: The current status of the document as a string. Can be in any case (will be converted to uppercase internally). Expected values include status constants like 'DRAFT', 'IN_REVIEW', 'IN_APPROVAL', 'APPROVED', 'PUBLISHED', 'EFFECTIVE', 'ARCHIVED', 'OBSOLETE', or custom statuses defined in settings.
Return Value
Type: str
Returns a string representing the next status in the document lifecycle. If the current status is at the end of the lifecycle (e.g., 'OBSOLETE') or not recognized, returns the same status unchanged. The returned status will be in uppercase format.
Dependencies
CDocs.config
Required Imports
from CDocs.config import settings
Usage Example
# Assuming status constants are defined
STATUS_DRAFT = 'DRAFT'
STATUS_IN_REVIEW = 'IN_REVIEW'
STATUS_IN_APPROVAL = 'IN_APPROVAL'
STATUS_APPROVED = 'APPROVED'
STATUS_PUBLISHED = 'PUBLISHED'
STATUS_EFFECTIVE = 'EFFECTIVE'
STATUS_ARCHIVED = 'ARCHIVED'
STATUS_OBSOLETE = 'OBSOLETE'
# Basic usage
current = 'draft'
next_status = get_next_status(current)
print(next_status) # Output: 'IN_REVIEW'
# At terminal state
current = 'OBSOLETE'
next_status = get_next_status(current)
print(next_status) # Output: 'OBSOLETE'
# With custom settings (in settings.py):
# settings.VALID_STATUS_TRANSITIONS = {
# 'DRAFT': ['IN_REVIEW', 'ARCHIVED'],
# 'IN_REVIEW': ['APPROVED']
# }
next_status = get_next_status('DRAFT')
print(next_status) # Output: 'IN_REVIEW' (first transition)
Best Practices
- Ensure all status constants (STATUS_DRAFT, STATUS_IN_REVIEW, etc.) are properly defined before using this function
- Configure settings.VALID_STATUS_TRANSITIONS for custom workflow logic rather than modifying the fallback flow
- The function always returns the first transition in the list if multiple transitions are available in settings
- Status comparison is case-insensitive (converted to uppercase), but returned values are uppercase
- For terminal states or unknown statuses, the function returns the input status unchanged, preventing invalid state transitions
- Consider validating the returned status before applying it to ensure it matches your expected workflow
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_version 75.6% similar
-
function get_status_after_approval 67.1% similar
-
function is_published_status 58.8% similar
-
function is_valid_status_transition 58.4% similar
-
function get_document_status_name 58.3% similar