Files
orion/app/modules/analytics/definition.py
Samir Boulahtit bd2c99a775 feat: complete analytics module self-containment
Migrate analytics module to fully self-contained structure:

- routes/api/vendor.py - API endpoints
- routes/pages/vendor.py - Page routes with full implementation
- services/stats_service.py - Business logic (moved from app/services)
- services/usage_service.py - Usage tracking (moved from app/services)
- schemas/stats.py - Pydantic schemas (moved from models/schema)
- models/__init__.py - Model exports
- templates/analytics/vendor/ - Templates (moved from app/templates)
- static/vendor/js/ - JavaScript (moved from static/vendor)
- locales/ - Translations (en, de, fr, lu)
- exceptions.py - Module exceptions

Removed legacy files:
- app/modules/analytics/routes/vendor.py (replaced by routes/pages/)
- static/admin/js/analytics.js (unused)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 22:21:21 +01:00

81 lines
2.6 KiB
Python

# app/modules/analytics/definition.py
"""
Analytics module definition.
Defines the analytics module including its features, menu items,
route configurations, and self-contained module settings.
"""
from app.modules.base import ModuleDefinition
from models.database.admin_menu_config import FrontendType
def _get_vendor_api_router():
"""Lazy import of vendor API router to avoid circular imports."""
from app.modules.analytics.routes.api.vendor import router
return router
def _get_vendor_page_router():
"""Lazy import of vendor page router to avoid circular imports."""
from app.modules.analytics.routes.pages.vendor import router
return router
# Analytics module definition
analytics_module = ModuleDefinition(
code="analytics",
name="Analytics & Reporting",
description="Dashboard analytics, custom reports, and data exports.",
version="1.0.0",
features=[
"basic_reports", # Basic reporting
"analytics_dashboard", # Analytics dashboard
"custom_reports", # Custom report builder
"export_reports", # Export to CSV/Excel
"usage_metrics", # Usage and performance metrics
],
menu_items={
FrontendType.ADMIN: [
# Analytics appears in dashboard for admin
],
FrontendType.VENDOR: [
"analytics", # Vendor analytics page
],
},
is_core=False,
# =========================================================================
# Self-Contained Module Configuration
# =========================================================================
is_self_contained=True,
services_path="app.modules.analytics.services",
models_path="app.modules.analytics.models",
schemas_path="app.modules.analytics.schemas",
exceptions_path="app.modules.analytics.exceptions",
# Module templates (namespaced as analytics/admin/*.html and analytics/vendor/*.html)
templates_path="templates",
# Module-specific translations (accessible via analytics.* keys)
locales_path="locales",
)
def get_analytics_module_with_routers() -> ModuleDefinition:
"""
Get analytics module with routers attached.
This function attaches the routers lazily to avoid circular imports
during module initialization.
Routers:
- vendor_api_router: API endpoints for vendor analytics
- vendor_page_router: Page routes for vendor analytics dashboard
"""
analytics_module.vendor_api_router = _get_vendor_api_router()
analytics_module.vendor_page_router = _get_vendor_page_router()
return analytics_module
__all__ = ["analytics_module", "get_analytics_module_with_routers"]