🔍 Code Extractor

function get_document_status_code

Maturity: 30

Retrieves a document status code from a dictionary lookup using the provided full name, returning the name itself if not found.

File:
/tf/active/vicechatdev/CDocs/settings_prod.py
Lines:
772 - 774
Complexity:
simple

Purpose

This function serves as a lookup utility to convert human-readable document status names into their corresponding status codes. It uses a predefined DOCUMENT_STATUSES dictionary to perform the mapping. If the provided name doesn't exist in the dictionary, it returns the input name unchanged, providing a safe fallback behavior. This is commonly used in document management systems to normalize status representations.

Source Code

def get_document_status_code(name):
    """Get document status code from full name."""
    return DOCUMENT_STATUSES.get(name, name)

Parameters

Name Type Default Kind
name - - positional_or_keyword

Parameter Details

name: The full name of the document status to look up. Expected to be a string representing a document status (e.g., 'Draft', 'Published', 'Archived'). Can be any value; if not found in DOCUMENT_STATUSES dictionary, the function returns this value unchanged.

Return Value

Returns the status code corresponding to the provided name from the DOCUMENT_STATUSES dictionary. If the name is not found in the dictionary, returns the input 'name' parameter unchanged. The return type is typically a string or the same type as values stored in DOCUMENT_STATUSES dictionary.

Usage Example

# Assuming DOCUMENT_STATUSES is defined as:
# DOCUMENT_STATUSES = {'Draft': 'DRF', 'Published': 'PUB', 'Archived': 'ARC'}

status_code = get_document_status_code('Draft')
print(status_code)  # Output: 'DRF'

# If status name not found, returns the input
unknown_status = get_document_status_code('Unknown')
print(unknown_status)  # Output: 'Unknown'

Best Practices

  • Ensure DOCUMENT_STATUSES dictionary is properly defined and accessible in the module scope before calling this function
  • The function provides safe fallback behavior by returning the input if not found, preventing KeyError exceptions
  • Consider validating the input 'name' parameter type if strict type checking is required
  • Document the expected structure and contents of DOCUMENT_STATUSES dictionary for maintainability
  • This function is stateless and thread-safe as long as DOCUMENT_STATUSES is not modified during execution

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_document_status_name 93.4% similar

    Retrieves the full document status name corresponding to a given status code by performing a reverse lookup in the DOCUMENT_STATUSES dictionary.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_document_type_code 76.2% similar

    Retrieves a document type code from a dictionary lookup using the provided document type name, returning the name itself if no mapping exists.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_document_type_name 72.3% similar

    Looks up and returns the full document type name corresponding to a given document type code by searching through a DOCUMENT_TYPES dictionary.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function get_status_color 72.0% similar

    Retrieves the color code associated with a given document status code from a configuration dictionary, returning a default gray color if the status is not found.

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function is_valid_document_status 64.9% similar

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

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