Introduces a module-driven context provider system that allows modules to dynamically contribute template context variables without hardcoding imports. Key changes: - Add context_providers field to ModuleDefinition in app/modules/base.py - Create unified get_context_for_frontend() that queries enabled modules only - Add context providers to CMS module (PLATFORM, STOREFRONT) - Add context providers to billing module (PLATFORM) - Fix SQLAlchemy cross-module relationship resolution (Order, AdminMenuConfig, MarketplaceImportJob) by ensuring models are imported before referencing - Document the entire system in docs/architecture/module-system.md Benefits: - Zero coupling: adding/removing modules requires no route handler changes - Lazy loading: module code only imported when that module is enabled - Per-platform customization: each platform loads only what it needs - Graceful degradation: one failing module doesn't break entire page Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
# app/modules/tenancy/models/__init__.py
|
|
"""
|
|
Tenancy module database models.
|
|
|
|
This is the canonical location for tenancy module models including:
|
|
- Platform, Company, Vendor, User management
|
|
- Admin platform assignments
|
|
- Vendor platform memberships
|
|
- Platform module configuration
|
|
- Vendor domains
|
|
"""
|
|
|
|
# Import models from other modules FIRST to resolve string-based relationship references.
|
|
# These imports are NOT re-exported, just ensure models are registered with SQLAlchemy
|
|
# before the tenancy models are loaded.
|
|
#
|
|
# Relationship chain being resolved:
|
|
# - Platform.admin_menu_configs -> "AdminMenuConfig" (in core module)
|
|
# - User.marketplace_import_jobs -> "MarketplaceImportJob" (in marketplace module)
|
|
# - Vendor.marketplace_import_jobs -> "MarketplaceImportJob" (in marketplace module)
|
|
from app.modules.core.models import AdminMenuConfig # noqa: F401
|
|
from app.modules.marketplace.models.marketplace_import_job import MarketplaceImportJob # noqa: F401
|
|
|
|
from app.modules.tenancy.models.admin import (
|
|
AdminAuditLog,
|
|
AdminSession,
|
|
AdminSetting,
|
|
ApplicationLog,
|
|
PlatformAlert,
|
|
)
|
|
from app.modules.tenancy.models.admin_platform import AdminPlatform
|
|
from app.modules.tenancy.models.company import Company
|
|
from app.modules.tenancy.models.platform import Platform
|
|
from app.modules.tenancy.models.platform_module import PlatformModule
|
|
from app.modules.tenancy.models.user import User, UserRole
|
|
from app.modules.tenancy.models.vendor import Role, Vendor, VendorUser, VendorUserType
|
|
from app.modules.tenancy.models.vendor_domain import VendorDomain
|
|
from app.modules.tenancy.models.vendor_platform import VendorPlatform
|
|
|
|
__all__ = [
|
|
# Admin models
|
|
"AdminAuditLog",
|
|
"AdminSession",
|
|
"AdminSetting",
|
|
"ApplicationLog",
|
|
"PlatformAlert",
|
|
# Admin-Platform junction
|
|
"AdminPlatform",
|
|
# Company
|
|
"Company",
|
|
# Platform
|
|
"Platform",
|
|
"PlatformModule",
|
|
# User
|
|
"User",
|
|
"UserRole",
|
|
# Vendor
|
|
"Vendor",
|
|
"VendorUser",
|
|
"VendorUserType",
|
|
"Role",
|
|
# Vendor configuration
|
|
"VendorDomain",
|
|
"VendorPlatform",
|
|
]
|