🔍 Code Extractor

function create_approval_panel_v1

Maturity: 46

Factory function that creates and initializes an approval workflow panel UI component for managing document approval cycles.

File:
/tf/active/vicechatdev/CDocs single class/ui/approval_panel.py
Lines:
640 - 672
Complexity:
moderate

Purpose

This function serves as a factory to instantiate an approval panel UI component within the CDocs document management system. It delegates to a generic workflow panel creator, specifically configured for approval workflows. The function includes error handling that returns a minimal fallback panel if initialization fails, ensuring the application remains functional even when errors occur. It's designed to be used in both standalone and embedded contexts within the CDocs application.

Source Code

def create_approval_panel(session_manager=None, parent_app=None, embedded=False):
    """Create and initialize an approval panel instance"""
    try:
        # Import from the base module
        from CDocs.ui.workflow_panel_base import create_workflow_panel
        
        # Use the generic function from workflow_panel_base
        return create_workflow_panel(
            workflow_type='APPROVAL',
            controller=None,  # Let the panel initialize the controller
            session_manager=session_manager,
            parent_app=parent_app,
            embedded=embedded
        )
                
    except Exception as e:
        logger.error(f"Error creating approval panel: {e}")
        logger.error(traceback.format_exc())
        
        # Return a minimal functioning panel
        minimal_panel = pn.Column(
            pn.pane.Markdown("# Approval Management"),
            pn.pane.Markdown(f"**Error loading approval panel:** {str(e)}")
        )
        minimal_panel.main_content = minimal_panel
        
        # Add minimal set_user method to avoid errors
        import types
        def minimal_set_user(obj, user):
            pass
        minimal_panel.set_user = types.MethodType(minimal_set_user, minimal_panel)
        
        return minimal_panel

Parameters

Name Type Default Kind
session_manager - None positional_or_keyword
parent_app - None positional_or_keyword
embedded - False positional_or_keyword

Parameter Details

session_manager: Optional SessionManager instance that handles user authentication and session state. If None, the panel may initialize its own session manager or operate with limited functionality. Expected type: SessionManager or None.

parent_app: Optional reference to the parent application instance that contains this panel. Used for inter-component communication and accessing shared application resources. Expected type: Application object or None.

embedded: Boolean flag indicating whether the panel is being embedded within another UI component (True) or used as a standalone panel (False). Affects layout and navigation behavior. Default: False.

Return Value

Returns a Panel UI component (typically a pn.Column or WorkflowPanelBase instance) representing the approval management interface. On success, returns a fully initialized workflow panel with approval-specific functionality. On error, returns a minimal pn.Column containing error messages and a stub set_user method to prevent downstream errors. The returned object always has a 'main_content' attribute and a 'set_user' method.

Dependencies

  • panel
  • pandas
  • logging
  • traceback
  • typing
  • datetime
  • types

Required Imports

import panel as pn
import logging
import traceback
import types
from CDocs.ui.workflow_panel_base import create_workflow_panel

Conditional/Optional Imports

These imports are only needed under specific conditions:

from CDocs.ui.workflow_panel_base import create_workflow_panel

Condition: always required for normal operation, imported inside try block for error handling

Required (conditional)

Usage Example

from CDocs.auth.session_manager import SessionManager
from CDocs.ui.approval_panel import create_approval_panel
import panel as pn

# Initialize Panel
pn.extension()

# Create session manager
session_mgr = SessionManager()

# Create standalone approval panel
approval_panel = create_approval_panel(
    session_manager=session_mgr,
    parent_app=None,
    embedded=False
)

# Set current user
from CDocs.models.user_extensions import DocUser
user = DocUser(username='john.doe', role='approver')
approval_panel.set_user(user)

# Display the panel
approval_panel.servable()

# Or create embedded panel for use within another app
embedded_panel = create_approval_panel(
    session_manager=session_mgr,
    parent_app=my_app,
    embedded=True
)

Best Practices

  • Always provide a session_manager for proper user authentication and authorization
  • Handle the returned panel gracefully - check for error messages in the UI if initialization fails
  • The function guarantees a return value even on error, so no need for additional null checks
  • When embedding, set embedded=True to ensure proper layout behavior
  • Call set_user() on the returned panel after creation to associate it with the current user
  • Ensure the logger is properly configured in the module scope before calling this function
  • The function delegates to create_workflow_panel with workflow_type='APPROVAL', so ensure that module supports this workflow type
  • The minimal fallback panel is functional but limited - monitor logs for initialization errors in production

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_approval_panel_v2 92.7% similar

    Factory function that creates and initializes an ApprovalPanel instance for managing document approvals, with error handling and fallback to a minimal panel on failure.

    From: /tf/active/vicechatdev/CDocs/ui/approval_panel.py
  • function create_approval_panel 90.1% 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
  • function create_workflow_panel 82.3% similar

    Factory function that creates and initializes workflow management panels (Review or Approval) with appropriate configuration, error handling, and fallback mechanisms.

    From: /tf/active/vicechatdev/CDocs single class/ui/workflow_panel_base.py
  • function create_review_panel_v1 80.6% similar

    Factory function that creates and initializes a review panel UI component for document review workflow management, with error handling and fallback to a minimal panel on failure.

    From: /tf/active/vicechatdev/CDocs single class/ui/review_panel.py
  • function create_review_panel 74.4% similar

    Factory function that creates and initializes a ReviewPanel instance with error handling, supporting both standalone and embedded modes for document review management.

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