🔍 Code Extractor

function is_editable_status

Maturity: 52

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

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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function is_published_status 80.1% similar

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

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

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

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_version 58.0% 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 is_valid_status_transition 56.2% similar

    Validates whether a transition from one status to another is allowed based on predefined valid status transitions.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_next_status 55.9% 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
← Back to Browse