function is_editable_status
Validates whether a given document status string allows editing by checking it against a predefined list of editable statuses.
/tf/active/vicechatdev/CDocs/models/document_status.py
27 - 42
simple
Purpose
This function provides a centralized way to determine if a document with a particular status can be edited. It performs case-insensitive comparison against a configuration-defined list of editable statuses (EDITABLE_STATUSES), ensuring consistent status validation across the application. Common use cases include form validation, permission checks, and UI state management for document editing features.
Source Code
def is_editable_status(status: str) -> bool:
"""
Check if a document status allows editing
Parameters
----------
status : str
Document status to check
Returns
-------
bool
True if the status allows editing, False otherwise
"""
# Convert to uppercase for case-insensitive comparison with settings
return status.upper() in EDITABLE_STATUSES
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
status |
str | - | positional_or_keyword |
Parameter Details
status: A string representing the current status of a document (e.g., 'draft', 'pending', 'approved'). The function performs case-insensitive comparison, so 'DRAFT', 'Draft', and 'draft' are treated identically. Should be a non-empty string representing a valid document status.
Return Value
Type: bool
Returns a boolean value: True if the provided status (after converting to uppercase) exists in the EDITABLE_STATUSES configuration list, indicating the document can be edited; False otherwise, indicating the document is locked or in a non-editable state.
Dependencies
CDocs.config
Required Imports
from CDocs.config import settings
Usage Example
from CDocs.config import settings
# Assuming EDITABLE_STATUSES is defined in settings as:
# EDITABLE_STATUSES = ['DRAFT', 'PENDING', 'IN_REVIEW']
def is_editable_status(status: str) -> bool:
return status.upper() in EDITABLE_STATUSES
# Example usage:
if is_editable_status('draft'):
print('Document can be edited')
else:
print('Document is locked')
# Case-insensitive checks:
print(is_editable_status('DRAFT')) # True
print(is_editable_status('Draft')) # True
print(is_editable_status('approved')) # False (assuming not in EDITABLE_STATUSES)
print(is_editable_status('pending')) # True
Best Practices
- Ensure EDITABLE_STATUSES is properly configured in settings before using this function
- The function assumes EDITABLE_STATUSES contains uppercase strings; maintain this convention in configuration
- Handle potential AttributeError if status is None by validating input before calling this function
- Consider caching the result if checking the same status multiple times in a single operation
- Use this function consistently across the application rather than duplicating status checks
- Document the valid status values and which ones are editable in your application's configuration documentation
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function is_published_status 80.1% similar
-
function is_valid_document_status 68.3% similar
-
function get_version 58.0% similar
-
function is_valid_status_transition 56.2% similar
-
function get_next_status 55.9% similar