function get_approval_workflow_templates
Retrieves approval workflow templates, optionally filtered by document type, and returns them in a standardized response format with success status and count.
/tf/active/vicechatdev/CDocs single class/controllers/approval_controller.py
2038 - 2041
simple
Purpose
This function serves as a controller endpoint to fetch approval workflow templates from the system. It acts as a wrapper around the base controller's template retrieval method, providing a consistent API response structure. The function is used to display available workflow templates to users when setting up approval processes for documents, allowing filtering by document type to show only relevant templates.
Source Code
def get_approval_workflow_templates(document_type: Optional[str] = None) -> Dict[str, Any]:
"""Get approval workflow templates."""
templates = _controller.get_approval_workflow_templates(document_type)
return {"success": True, "templates": templates, "total": len(templates)}
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
document_type |
Optional[str] | None | positional_or_keyword |
Parameter Details
document_type: Optional string parameter to filter workflow templates by document type. When provided, only templates applicable to the specified document type are returned. When None (default), all available workflow templates are returned regardless of document type. Expected values would be document type identifiers defined in the system (e.g., 'SOP', 'Policy', 'Procedure').
Return Value
Type: Dict[str, Any]
Returns a dictionary with three keys: 'success' (boolean, always True indicating successful retrieval), 'templates' (list of workflow template objects/dictionaries containing template configurations), and 'total' (integer representing the count of templates returned). The structure follows a standard API response pattern for consistency across the application.
Dependencies
typingdatetimeloggingtracebackuuidCDocs
Required Imports
from typing import Dict, Any, Optional
from CDocs.controllers import log_controller_action
Usage Example
# Assuming the function is imported from CDocs.controllers.approval_controller
from CDocs.controllers.approval_controller import get_approval_workflow_templates
# Get all workflow templates
result = get_approval_workflow_templates()
print(f"Found {result['total']} templates")
for template in result['templates']:
print(f"Template: {template}")
# Get templates for a specific document type
sop_templates = get_approval_workflow_templates(document_type='SOP')
if sop_templates['success']:
print(f"Found {sop_templates['total']} SOP templates")
for template in sop_templates['templates']:
print(f"SOP Template: {template}")
# Get templates for policies
policy_templates = get_approval_workflow_templates(document_type='Policy')
print(f"Policy templates available: {policy_templates['total']}")
Best Practices
- This function is decorated with @log_controller_action which logs all invocations - ensure logging is properly configured
- The function always returns success=True; error handling should be implemented in the underlying _controller.get_approval_workflow_templates method
- Use the document_type parameter to reduce the result set when you know the specific document type to improve performance
- The returned templates list structure depends on the underlying controller implementation - verify the template schema before use
- This function appears to be part of a larger CDocs system - ensure the _controller instance is properly initialized before calling
- Consider implementing pagination if the number of templates can be large
- The function does not require explicit permissions checking via decorator, but the underlying controller may enforce permissions
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_approval_workflow 82.8% similar
-
function get_document_approval_cycles_v1 72.3% similar
-
function get_user_assigned_approvals_v1 70.7% similar
-
function get_user_assigned_approvals_v2 69.5% similar
-
class ApprovalControllerBase 67.1% similar