🔍 Code Extractor

function get_document_v6

Maturity: 45

Retrieves all versions of a document from the database given its unique identifier (UID).

File:
/tf/active/vicechatdev/document_controller_backup.py
Lines:
2483 - 2519
Complexity:
simple

Purpose

This function serves as a controller method to fetch version history for a specific document in a document management system. It handles error cases (missing UID, database errors) and returns a standardized response dictionary containing the document's version list. It's designed to be used in document version tracking and audit trail features.

Source Code

def get_document_versions(document_uid):
    """
    Get all versions for a document.
    
    Parameters
    ----------
    document_uid : str
        Document UID
        
    Returns
    -------
    dict
        Dictionary with versions list
    """
    if not document_uid:
        return {"success": False, "message": "No document UID provided"}
    
    try:
        # Import here to avoid circular imports
        
        
        # Get versions from database
        versions = get_document_versions_from_db(document_uid)
        
        # Format response
        return {
            "success": True,
            "document_uid": document_uid,
            "versions": versions
        }
    except Exception as e:
        import logging
        logger = logging.getLogger("CDocs.controllers.document_controller")
        logger.error(f"Error getting document versions: {e}")
        import traceback
        logger.error(traceback.format_exc())
        return {"success": False, "message": str(e)}

Parameters

Name Type Default Kind
document_uid - - positional_or_keyword

Parameter Details

document_uid: A string representing the unique identifier of the document whose versions are to be retrieved. Must be a non-empty string. If empty or None, the function returns an error response.

Return Value

Returns a dictionary with the following structure: On success: {'success': True, 'document_uid': str, 'versions': list} where 'versions' contains the list of document versions from the database. On failure: {'success': False, 'message': str} where 'message' contains the error description.

Dependencies

  • logging
  • traceback
  • CDocs.db.db_operations
  • CDocs.config.settings
  • CDocs.db.schema_manager
  • CDocs.models.document
  • CDocs.models.user_extensions
  • CDocs.utils.document_processor
  • CDocs.utils.notifications
  • CDocs.utils.audit_trail
  • CDocs.controllers
  • CDocs.controllers.filecloud_controller
  • CDocs.utils.document_converter
  • CDocs.models.document_status
  • CDocs.utils.filecloud_integration
  • CDocs.models.review
  • CDocs.models.approval
  • panel
  • uuid
  • os
  • tempfile
  • datetime
  • io
  • shutil
  • typing
  • config
  • random

Required Imports

from CDocs.db.db_operations import get_document_versions_from_db

Conditional/Optional Imports

These imports are only needed under specific conditions:

import logging

Condition: only when an exception occurs during execution

Required (conditional)
import traceback

Condition: only when an exception occurs and detailed error logging is needed

Required (conditional)

Usage Example

from CDocs.controllers.document_controller import get_document_versions

# Get versions for a specific document
document_uid = 'doc-12345-abcde'
result = get_document_versions(document_uid)

if result['success']:
    print(f"Found {len(result['versions'])} versions for document {result['document_uid']}")
    for version in result['versions']:
        print(f"Version: {version}")
else:
    print(f"Error: {result['message']}")

# Handle missing UID
result = get_document_versions('')
print(result)  # {'success': False, 'message': 'No document UID provided'}

Best Practices

  • Always check the 'success' field in the returned dictionary before accessing 'versions' to avoid KeyError
  • Provide a valid non-empty document_uid to avoid immediate error response
  • The function uses lazy imports for logging and traceback to avoid circular dependencies - this is intentional
  • Error messages are logged with full stack traces for debugging purposes
  • The function returns a consistent dictionary structure for both success and failure cases, making it easy to handle responses uniformly
  • Consider implementing caching if this function is called frequently for the same document_uid

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_document_v2 87.4% similar

    Retrieves detailed information about a specific document version by its UID, including associated document context and version status.

    From: /tf/active/vicechatdev/document_controller_backup.py
  • function get_document_v5 87.3% similar

    Retrieves all versions of a controlled document from a Neo4j graph database, including metadata about which version is current.

    From: /tf/active/vicechatdev/CDocs/db/db_operations.py
  • function get_document_v1 81.5% similar

    Retrieves comprehensive details of a controlled document by its UID, including optional version history, review cycles, and approval workflows.

    From: /tf/active/vicechatdev/CDocs/controllers/document_controller.py
  • function get_document 80.8% similar

    Retrieves comprehensive details of a controlled document by its UID, with optional inclusion of version history, review cycles, and approval cycles.

    From: /tf/active/vicechatdev/document_controller_backup.py
  • function compare_document_versions 72.8% similar

    Compares two document versions by their UIDs and generates a summary of changes including metadata differences and hash comparisons.

    From: /tf/active/vicechatdev/CDocs/utils/document_processor.py
← Back to Browse