🔍 Code Extractor

function get_status_color

Maturity: 32

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.

File:
/tf/active/vicechatdev/CDocs/settings_prod.py
Lines:
784 - 788
Complexity:
simple

Purpose

This function provides a centralized way to map document status codes to their corresponding color representations (hex color codes). It's typically used in UI rendering to visually distinguish different document statuses. The function ensures consistent color coding across the application by referencing a global DOCUMENT_STATUS_CONFIG dictionary and provides a fallback default color for unknown statuses.

Source Code

def get_status_color(status_code):
    """Get the color for a status code."""
    if status_code in DOCUMENT_STATUS_CONFIG:
        return DOCUMENT_STATUS_CONFIG[status_code].get('color', '#6c757d')
    return '#6c757d'  # Default gray

Parameters

Name Type Default Kind
status_code - - positional_or_keyword

Parameter Details

status_code: The status code identifier for a document. This can be any hashable type (typically string or integer) that serves as a key in the DOCUMENT_STATUS_CONFIG dictionary. Examples might include 'draft', 'published', 'archived', or numeric codes like 1, 2, 3 depending on the application's status system.

Return Value

Returns a string representing a hex color code (e.g., '#6c757d'). If the status_code exists in DOCUMENT_STATUS_CONFIG and has a 'color' key, that color value is returned. Otherwise, returns '#6c757d' (a gray color) as the default. The return type is always a string.

Usage Example

# First, define the required configuration
DOCUMENT_STATUS_CONFIG = {
    'draft': {'color': '#ffc107', 'label': 'Draft'},
    'published': {'color': '#28a745', 'label': 'Published'},
    'archived': {'color': '#6c757d', 'label': 'Archived'}
}

# Now use the function
color = get_status_color('draft')
print(color)  # Output: '#ffc107'

color = get_status_color('published')
print(color)  # Output: '#28a745'

color = get_status_color('unknown_status')
print(color)  # Output: '#6c757d' (default gray)

Best Practices

  • Ensure DOCUMENT_STATUS_CONFIG is properly initialized before calling this function to avoid NameError
  • The DOCUMENT_STATUS_CONFIG dictionary should be defined as a module-level constant for consistency
  • Consider validating that color values in DOCUMENT_STATUS_CONFIG are valid hex color codes
  • The function is safe to call with any status_code value as it always returns a valid color (default fallback)
  • For type safety, consider adding type hints: def get_status_color(status_code: str) -> str:
  • If DOCUMENT_STATUS_CONFIG is large or frequently accessed, ensure it's efficiently structured (dictionary lookup is O(1))

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_document_status_name 72.8% 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_status_code 72.0% similar

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

    From: /tf/active/vicechatdev/CDocs/settings_prod.py
  • function is_valid_document_status 64.7% 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 54.5% 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 get_next_status 54.1% 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