
- Add HTML templates for clean separation of concerns - Add structured data models for type safety - Add template renderer for Jinja2 integration - Add templated dashboard implementation - Demonstrates 95% file size reduction potential
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Run Templated Trading Dashboard
|
|
Demonstrates the new MVC template-based architecture
|
|
"""
|
|
import logging
|
|
import sys
|
|
import os
|
|
|
|
# Add project root to path
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from web.templated_dashboard import create_templated_dashboard
|
|
from web.dashboard_model import create_sample_dashboard_data
|
|
from web.template_renderer import DashboardTemplateRenderer
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def main():
|
|
"""Main function to run the templated dashboard"""
|
|
try:
|
|
logger.info("=== TEMPLATED DASHBOARD DEMO ===")
|
|
|
|
# Test the template system first
|
|
logger.info("Testing template system...")
|
|
|
|
# Create sample data
|
|
sample_data = create_sample_dashboard_data()
|
|
logger.info(f"Created sample data with {len(sample_data.metrics)} metrics")
|
|
|
|
# Test template renderer
|
|
renderer = DashboardTemplateRenderer()
|
|
logger.info("Template renderer initialized")
|
|
|
|
# Create templated dashboard
|
|
logger.info("Creating templated dashboard...")
|
|
dashboard = create_templated_dashboard()
|
|
|
|
logger.info("Dashboard created successfully!")
|
|
logger.info("Template-based MVC architecture features:")
|
|
logger.info(" ✓ HTML templates separated from Python code")
|
|
logger.info(" ✓ Data models for structured data")
|
|
logger.info(" ✓ Template renderer for clean separation")
|
|
logger.info(" ✓ Easy to modify HTML without touching Python")
|
|
logger.info(" ✓ Reusable components and templates")
|
|
|
|
# Run the dashboard
|
|
logger.info("Starting templated dashboard server...")
|
|
dashboard.run_server(host='127.0.0.1', port=8051, debug=False)
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error running templated dashboard: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |