function get_document_type
Retrieves configuration details for a specific document type by looking it up in DOCUMENT_CONFIG or DOCUMENT_TYPES, returning a dictionary with document metadata or an empty dict if not found.
/tf/active/vicechatdev/CDocs/settings_prod.py
513 - 538
simple
Purpose
This function serves as a lookup utility to fetch document type configuration details from predefined data structures. It first checks DOCUMENT_CONFIG for extended configuration, then falls back to DOCUMENT_TYPES for basic configuration, and returns structured metadata including prefix, name, numbering format, template, and approval levels. This is useful in document management systems where different document types require different handling and formatting rules.
Source Code
def get_document_type(doc_type: str) -> Dict[str, Any]:
"""
Get details for a specific document type.
Args:
doc_type: Document type code (e.g., 'SOP')
Returns:
Dictionary with document type details or empty dict if not found
"""
# Check if the doc_type exists in the extended dictionary
if (doc_type in DOCUMENT_CONFIG):
return DOCUMENT_CONFIG[doc_type]
# If just using the simple list, return a basic dictionary
if (doc_type in DOCUMENT_TYPES):
return {
'prefix': doc_type[:3].upper(),
'name': doc_type,
'numbering_format': '{prefix}-{dept}-{number:03d}',
'template': None,
'approval_levels': 1
}
# Not found in either place
return {}
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
doc_type |
str | - | positional_or_keyword |
Parameter Details
doc_type: A string representing the document type code (e.g., 'SOP', 'WI', 'FORM'). This code is used to look up the corresponding configuration in DOCUMENT_CONFIG or DOCUMENT_TYPES. The function is case-sensitive and expects the exact code as stored in the configuration structures.
Return Value
Type: Dict[str, Any]
Returns a Dict[str, Any] containing document type details. If found in DOCUMENT_CONFIG, returns the full configuration dictionary as defined there. If found only in DOCUMENT_TYPES, returns a basic dictionary with keys: 'prefix' (first 3 uppercase characters), 'name' (the doc_type itself), 'numbering_format' (a template string), 'template' (None), and 'approval_levels' (1). Returns an empty dictionary {} if the doc_type is not found in either data structure.
Required Imports
from typing import Dict
from typing import Any
Usage Example
# Assuming DOCUMENT_CONFIG and DOCUMENT_TYPES are defined
DOCUMENT_CONFIG = {
'SOP': {
'prefix': 'SOP',
'name': 'Standard Operating Procedure',
'numbering_format': '{prefix}-{dept}-{number:04d}',
'template': 'sop_template.docx',
'approval_levels': 3
}
}
DOCUMENT_TYPES = ['WI', 'FORM']
# Get extended configuration
sop_config = get_document_type('SOP')
print(sop_config)
# Output: {'prefix': 'SOP', 'name': 'Standard Operating Procedure', ...}
# Get basic configuration
wi_config = get_document_type('WI')
print(wi_config)
# Output: {'prefix': 'WI', 'name': 'WI', 'numbering_format': '{prefix}-{dept}-{number:03d}', ...}
# Handle not found
unknown = get_document_type('UNKNOWN')
print(unknown)
# Output: {}
Best Practices
- Ensure DOCUMENT_CONFIG and DOCUMENT_TYPES are properly defined and accessible in the module scope before calling this function
- Always check if the returned dictionary is empty before accessing its keys to avoid KeyError exceptions
- Use consistent document type codes (case-sensitive) across your application
- Consider caching results if this function is called frequently with the same doc_type values
- The function assumes DOCUMENT_CONFIG takes precedence over DOCUMENT_TYPES, so ensure your configuration hierarchy is intentional
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_document_types 78.4% similar
-
function get_document_type_name 71.9% similar
-
function get_document_type_code 71.6% similar
-
function get_document_permissions 56.6% similar
-
function get_document_status_code 54.8% similar