function create_embedded_admin_panel
Creates and returns an embedded AdminPanel instance configured for integration within other application interfaces without its own template or session manager.
/tf/active/vicechatdev/CDocs/ui/admin_panel.py
1734 - 1758
moderate
Purpose
This function instantiates an AdminPanel component in embedded mode, designed to be integrated into existing application interfaces. It bypasses the need for a standalone template and session manager by relying on the parent application's infrastructure. This is useful when you want to embed administrative functionality within a larger application without creating a separate admin interface. The function includes error handling and logging for debugging purposes.
Source Code
def create_embedded_admin_panel(parent_app=None):
"""
Create an embedded admin panel for use within other interfaces.
Args:
parent_app: Reference to the parent application
Returns:
AdminPanel: Configured admin panel instance in embedded mode
"""
try:
admin_panel = AdminPanel(
template=None, # No template needed for embedded mode
session_manager=None, # Will use parent app's user
parent_app=parent_app,
embedded=True
)
logger.info("Embedded admin panel created successfully")
return admin_panel
except Exception as e:
logger.error(f"Error creating embedded admin panel: {e}")
logger.error(f"Traceback: {traceback.format_exc()}")
raise
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
parent_app |
- | None | positional_or_keyword |
Parameter Details
parent_app: Optional reference to the parent application object. This allows the embedded admin panel to access parent application resources, user sessions, and context. Defaults to None if no parent application is provided. The parent_app should typically be an application instance that has its own session management and user authentication.
Return Value
Returns an AdminPanel instance configured in embedded mode. The AdminPanel object has template=None (no standalone UI template), session_manager=None (uses parent app's session), parent_app set to the provided parent_app parameter, and embedded=True flag. If an error occurs during creation, the function raises an exception after logging the error details.
Dependencies
loggingtracebackpanelpandasnumpymatplotlibparam
Required Imports
import logging
import traceback
import panel as pn
from CDocs.models.user_extensions import DocUser
from CDocs.controllers.admin_controller import get_system_stats, get_users, create_user, update_user, delete_user, get_departments, get_user_activity, get_document_stats
from CDocs.controllers import ResourceNotFoundError, ValidationError, PermissionError, BusinessRuleError
from CDocs.auth.session_manager import SessionManager
from CDocs.utils.notifications import NotificationManager
from CDocs.db.db_operations import run_query
from CDocs.config import settings, permissions
Usage Example
import logging
import traceback
from my_app import MyParentApp
# Initialize logger
logger = logging.getLogger(__name__)
# Create parent application instance
parent_app = MyParentApp()
# Create embedded admin panel
try:
admin_panel = create_embedded_admin_panel(parent_app=parent_app)
# Use the admin panel within your application
# For example, add it to a layout:
# layout = pn.Column(parent_app.main_content, admin_panel)
except Exception as e:
print(f"Failed to create admin panel: {e}")
# Or create without parent app
admin_panel_standalone = create_embedded_admin_panel()
Best Practices
- Always wrap calls to this function in try-except blocks to handle potential initialization errors
- Ensure the parent_app parameter has proper session management and user authentication before passing it
- Initialize a logger before calling this function to capture error messages
- The AdminPanel class must be defined in the same module or imported before calling this function
- When using in embedded mode, ensure the parent application handles user permissions and authentication
- Check that all CDocs dependencies (config, models, controllers, auth, utils, db) are properly installed and configured
- Consider the lifecycle of the parent_app - the embedded panel may maintain references to it
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_admin_panel 84.5% similar
-
function get_admin_view 75.1% similar
-
function create_approval_panel 64.5% similar
-
function create_approval_panel_v1 62.4% similar
-
function create_review_panel 58.6% similar