🔍 Code Extractor

function create_document_detail

Maturity: 46

Factory function that creates and initializes a DocumentDetail panel component, optionally loading a specific document by its UID.

File:
/tf/active/vicechatdev/document_detail_backup.py
Lines:
2132 - 2155
Complexity:
simple

Purpose

This function serves as a factory/constructor for creating DocumentDetail panel instances in a controlled document management system. It encapsulates the instantiation logic and provides optional document loading functionality. The function is designed to be used in UI contexts where document detail views need to be dynamically created, either as standalone panels or as part of a larger application interface. It supports both creating empty detail panels and pre-loading specific documents.

Source Code

def create_document_detail(parent_app=None, document_uid=None):
    """
    Create a document detail panel.
    
    Parameters
    ----------
    parent_app : ControlledDocumentApp, optional
        Parent application
    document_uid : str, optional
        UID of document to load
    
    Returns
    -------
    DocumentDetail
        Document detail panel
    """
    # Create document detail instance
    doc_detail = DocumentDetail(parent_app=parent_app)
    
    # Load document if UID provided
    if document_uid:
        doc_detail.load_document(document_uid=document_uid)
    
    return doc_detail

Parameters

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

Parameter Details

parent_app: Optional reference to a ControlledDocumentApp instance that serves as the parent application context. This parameter enables the DocumentDetail panel to access application-level resources, settings, and state. Can be None for standalone usage. Expected type: ControlledDocumentApp or None.

document_uid: Optional unique identifier (UID) string for a document to be loaded immediately upon panel creation. If provided, the function will call load_document() on the created instance. Can be None to create an empty panel. Expected type: str or None.

Return Value

Returns a fully initialized DocumentDetail instance. This is a Panel-based UI component that displays detailed information about a controlled document, including metadata, versions, reviews, approvals, and audit history. If document_uid was provided, the returned instance will have that document's data already loaded; otherwise, it will be an empty panel ready to load a document later.

Dependencies

  • panel
  • param
  • pandas
  • CDocs

Required Imports

from CDocs.views.document_detail import DocumentDetail

Usage Example

# Example 1: Create empty document detail panel
from CDocs.views.document_detail import create_document_detail

doc_panel = create_document_detail()
# Panel is ready to load a document later via doc_panel.load_document()

# Example 2: Create panel with specific document loaded
from CDocs.views.document_detail import create_document_detail

doc_panel = create_document_detail(
    parent_app=my_app_instance,
    document_uid='DOC-12345'
)
# Panel is created with document DOC-12345 already loaded

# Example 3: Use in Panel application
import panel as pn
from CDocs.views.document_detail import create_document_detail

pn.extension()
app = pn.template.BootstrapTemplate(title='Document Viewer')
doc_detail = create_document_detail(document_uid='DOC-67890')
app.main.append(doc_detail)
app.servable()

Best Practices

  • Always handle cases where document_uid might reference a non-existent document by wrapping calls in try-except blocks
  • Pass parent_app when creating panels within a larger application context to ensure proper resource sharing and state management
  • Consider lazy loading documents (pass document_uid=None initially) for better performance when creating multiple panels
  • Ensure proper session management and authentication is established before creating document detail panels that will load sensitive documents
  • The DocumentDetail class likely has additional methods beyond load_document() - consult its documentation for full functionality
  • This function is a thin wrapper; for complex initialization logic, consider extending DocumentDetail class instead

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_training_dashboard 63.3% 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
  • function get_document_v1 61.0% 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 create_admin_panel 60.4% similar

    Factory function that creates and returns a configured AdminPanel instance with optional template, session management, parent application reference, and embedding mode.

    From: /tf/active/vicechatdev/CDocs/ui/admin_panel.py
  • function get_document 60.1% 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 create_approval_panel 58.6% similar

    Factory function that creates and initializes an ApprovalPanel instance with error handling, supporting both standalone and embedded modes for document approval management.

    From: /tf/active/vicechatdev/CDocs/ui/approval_panel_bis.py
← Back to Browse