🔍 Code Extractor

function create_training_management

Maturity: 34

Factory function that instantiates and returns a TrainingManagement object with optional parent application and document UID parameters.

File:
/tf/active/vicechatdev/CDocs/ui/training_management.py
Lines:
756 - 758
Complexity:
simple

Purpose

This function serves as a factory/constructor wrapper for creating TrainingManagement instances in a document control system. It provides a simplified interface for instantiating training management components, which likely handle training records, assignments, and tracking for controlled documents. The function allows optional binding to a parent application and association with a specific document through its UID.

Source Code

def create_training_management(parent_app=None, document_uid: str = None):
    """Create a training management instance."""
    return TrainingManagement(parent_app=parent_app, document_uid=document_uid)

Parameters

Name Type Default Kind
parent_app - None positional_or_keyword
document_uid str None positional_or_keyword

Parameter Details

parent_app: Optional reference to a parent application object. Defaults to None. This parameter likely enables the TrainingManagement instance to interact with or be embedded within a larger application context, potentially for UI integration or shared state management.

document_uid: Optional string identifier (UID) for a specific controlled document. Defaults to None. When provided, the TrainingManagement instance will be associated with and manage training for that particular document. Expected to be a unique string identifier conforming to the document identification scheme used in the system.

Return Value

Returns an instance of the TrainingManagement class. This object provides methods and properties for managing document training, including creating training records, tracking completion, assigning training to users, and managing training workflows. The returned instance is configured with the provided parent_app and document_uid parameters.

Dependencies

  • panel
  • param
  • pandas
  • logging
  • typing
  • re
  • traceback
  • datetime

Required Imports

from CDocs.config import settings
from CDocs.config import permissions
from CDocs.models.user_extensions import DocUser
from CDocs.models.document import ControlledDocument
from CDocs.models.training import DocumentTraining
from CDocs.controllers import training_controller
from CDocs.ui.base_ui import BaseUIComponent
from CDocs.db import db_operations

Usage Example

# Basic usage without parameters
training_mgmt = create_training_management()

# Usage with document UID only
training_mgmt = create_training_management(document_uid='DOC-12345')

# Usage with parent app and document UID
from my_app import MyApplication
app = MyApplication()
training_mgmt = create_training_management(parent_app=app, document_uid='DOC-12345')

# The returned object can then be used to manage training
# training_mgmt.assign_training(user_id='user123')
# training_mgmt.track_completion()

Best Practices

  • Use this factory function instead of directly instantiating TrainingManagement to maintain consistent initialization patterns
  • Provide document_uid when creating training management for a specific document to ensure proper context
  • Pass parent_app when integrating with a larger application to enable proper component communication
  • Ensure the CDocs package and all its dependencies are properly installed and configured before calling this function
  • Verify that the document_uid exists in the system before creating a training management instance for it
  • Consider error handling around this function call as it may fail if the TrainingManagement class initialization encounters issues with database connections or configuration

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_training_completion 78.3% similar

    Factory function that instantiates and returns a TrainingCompletion object for managing training completion workflows in a document control system.

    From: /tf/active/vicechatdev/CDocs/ui/training_completion.py
  • class TrainingManagement 70.4% similar

    UI component for managing document training.

    From: /tf/active/vicechatdev/CDocs/ui/training_management.py
  • function create_training_dashboard 65.7% similar

    Factory function that creates and initializes a TrainingDashboard instance with optional user context from a parent application.

    From: /tf/active/vicechatdev/CDocs/ui/training_dashboard.py
  • class DocumentTraining 64.8% similar

    A model class that manages training requirements and assignments for controlled documents, including enabling/disabling training, assigning training to users, and tracking training status.

    From: /tf/active/vicechatdev/CDocs/models/training.py
  • function assign_user_training 64.6% similar

    Assigns training requirements to multiple users for a specific controlled document, validating permissions, document training status, and user existence before creating assignments.

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