🔍 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_published_status_v1 82.1% similar

    Checks whether a given status value belongs to the published/non-editable status group by verifying its membership in NON_EDITABLE_STATUSES.

    From: /tf/active/vicechatdev/CDocs single class/config/settings.py
  • 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_editable_status_v1 64.5% similar

    Validates whether a given status value belongs to the predefined group of editable statuses by checking membership in the EDITABLE_STATUSES constant.

    From: /tf/active/vicechatdev/CDocs single class/config/settings.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 publish_document_v2 60.8% similar

    Publishes a controlled document by changing its status to PUBLISHED or EFFECTIVE based on the effective date, with audit logging and notifications.

    From: /tf/active/vicechatdev/CDocs copy/controllers/document_controller.py
← Back to Browse