function is_published_status
Validates whether a document status string represents a published or non-editable state by checking against a predefined list of non-editable statuses.
/tf/active/vicechatdev/CDocs/models/document_status.py
44 - 59
simple
Purpose
This function provides a centralized way to determine if a document is in a published or non-editable state, which is useful for enforcing business rules around document editing permissions. It performs case-insensitive comparison against a configuration-defined list of non-editable statuses, making it easy to control document workflow states across an application.
Source Code
def is_published_status(status: str) -> bool:
"""
Check if a document status is in a published/non-editable state
Parameters
----------
status : str
Document status to check
Returns
-------
bool
True if the status is published/non-editable, False otherwise
"""
# Convert to uppercase for case-insensitive comparison with settings
return status.upper() in NON_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., 'published', 'draft', 'archived'). The function performs case-insensitive comparison, so 'Published', 'PUBLISHED', and 'published' are treated identically. Expected to be a non-empty string representing a valid document status.
Return Value
Type: bool
Returns a boolean value: True if the provided status is found in the NON_EDITABLE_STATUSES configuration list (indicating the document is published or non-editable), False otherwise (indicating the document can be edited).
Dependencies
CDocs.config
Required Imports
from CDocs.config import settings
Usage Example
# Assuming NON_EDITABLE_STATUSES = ['PUBLISHED', 'ARCHIVED', 'LOCKED'] in settings
from CDocs.config import settings
def is_published_status(status: str) -> bool:
return status.upper() in NON_EDITABLE_STATUSES
# Example usage
doc_status = 'published'
if is_published_status(doc_status):
print('Document cannot be edited')
else:
print('Document can be edited')
# Case-insensitive check
print(is_published_status('Published')) # True
print(is_published_status('DRAFT')) # False
print(is_published_status('archived')) # True
Best Practices
- Ensure NON_EDITABLE_STATUSES is defined in settings before calling this function to avoid NameError
- Define NON_EDITABLE_STATUSES as uppercase strings in the configuration for consistency
- Consider using a set for NON_EDITABLE_STATUSES in settings for O(1) lookup performance if the list is large
- Always pass a valid string to avoid AttributeError when calling .upper() method
- Use this function consistently across the application rather than duplicating status checks to maintain single source of truth
- Document the valid status values and which ones are considered non-editable in your application's documentation
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function is_editable_status 80.1% similar
-
function is_valid_document_status 62.5% similar
-
function get_next_status 58.8% similar
-
function get_version 56.6% similar
-
function publish_document 56.5% similar