function log_training_event
A wrapper function that logs training-related events by delegating to a generic log_event function with pre-configured resource type.
/tf/active/vicechatdev/CDocs/utils/audit_trail.py
1005 - 1029
simple
Purpose
This function provides a specialized interface for logging training events in a document management system. It simplifies the logging process by automatically setting the resource_type to 'TrainingEvent' and mapping document_uid to resource_uid, making it easier to track training-related activities such as document reviews, training completions, or learning interactions.
Source Code
def log_training_event(
event_type: str,
user: DocUser,
document_uid: str,
details: Optional[Dict[str, Any]] = None
) -> bool:
"""
Log a training-related event.
Args:
event_type: Type of training event
user: User performing the action
document_uid: UID of the document
details: Additional event details
Returns:
True if logged successfully
"""
return log_event(
event_type=event_type,
user=user,
resource_uid=document_uid,
resource_type="TrainingEvent",
details=details
)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
event_type |
str | - | positional_or_keyword |
user |
DocUser | - | positional_or_keyword |
document_uid |
str | - | positional_or_keyword |
details |
Optional[Dict[str, Any]] | None | positional_or_keyword |
Parameter Details
event_type: A string identifier specifying the type of training event being logged (e.g., 'training_started', 'training_completed', 'document_reviewed'). This categorizes the event for later filtering and analysis.
user: A DocUser object representing the user who performed the training action. This object contains user identification and authentication information necessary for audit trails.
document_uid: A string containing the unique identifier (UID) of the document associated with this training event. This links the event to a specific training document or resource.
details: An optional dictionary containing additional metadata about the event. Can include any key-value pairs relevant to the specific training event, such as scores, duration, completion status, or custom attributes. Defaults to None if not provided.
Return Value
Type: bool
Returns a boolean value indicating whether the event was successfully logged. Returns True if the log_event function successfully recorded the training event to the database, False otherwise. This allows callers to verify that the logging operation completed successfully.
Dependencies
logginguuidtypingdatetimejsonCDocs
Required Imports
from typing import Dict, Any, Optional
from CDocs.models.user_extensions import DocUser
Usage Example
from CDocs.models.user_extensions import DocUser
from typing import Dict, Any
# Assume user object is already authenticated and available
user = DocUser(uid='user123', username='john_doe')
# Log a training completion event
success = log_training_event(
event_type='training_completed',
user=user,
document_uid='doc_abc123',
details={
'score': 95,
'duration_minutes': 45,
'completion_date': '2024-01-15',
'passed': True
}
)
if success:
print('Training event logged successfully')
else:
print('Failed to log training event')
# Log a simple training start event without details
log_training_event(
event_type='training_started',
user=user,
document_uid='doc_abc123'
)
Best Practices
- Always check the return value to ensure the event was logged successfully before proceeding with critical operations
- Use consistent event_type strings across your application to enable effective filtering and reporting
- Include relevant details in the details dictionary to provide context for future auditing and analysis
- Ensure the DocUser object is properly authenticated before logging events to maintain audit trail integrity
- Verify that document_uid corresponds to an actual document in the system before logging
- Consider implementing error handling around this function call in production code
- Use descriptive event_type names that clearly indicate the action being logged (e.g., 'training_module_completed' rather than 'done')
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function log_document_lifecycle_event 74.4% similar
-
function log_event 73.1% similar
-
function log_version_event 71.2% similar
-
function log_approval_event 70.5% similar
-
function log_review_event 69.5% similar