🔍 Code Extractor

function is_published_status

Maturity: 53

Validates whether a document status string represents a published or non-editable state by checking against a predefined list of non-editable statuses.

File:
/tf/active/vicechatdev/CDocs/models/document_status.py
Lines:
44 - 59
Complexity:
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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function is_editable_status 80.1% similar

    Validates whether a given document status string allows editing by checking it against a predefined list of editable statuses.

    From: /tf/active/vicechatdev/CDocs/models/document_status.py
  • function is_valid_document_status 62.5% similar

    Validates whether a given status code exists in the DOCUMENT_STATUS_CONFIG configuration.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_next_status 58.8% 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_version 56.6% 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
  • function publish_document 56.5% similar

    Publishes an approved controlled document by converting it to PDF with signatures and audit trail, uploading to FileCloud, and updating the document status to PUBLISHED.

    From: /tf/active/vicechatdev/document_controller_backup.py
← Back to Browse