Phase 1 - Foundation: - Add app/modules/contracts/ with Protocol definitions for cross-module communication (ServiceProtocol, ContentServiceProtocol, MediaServiceProtocol) - Enhance app/modules/base.py ModuleDefinition with self-contained module support (is_self_contained, services_path, models_path, etc.) - Update app/templates_config.py with multi-directory template loading using Jinja2 ChoiceLoader for module templates Phase 2 - CMS Pilot Module: - Migrate CMS service to app/modules/cms/services/content_page_service.py - Create app/modules/cms/exceptions.py with CMS-specific exceptions - Configure app/modules/cms/models/ to re-export ContentPage from canonical location (models.database) to avoid circular imports - Update cms_module definition with is_self_contained=True and paths - Add backwards compatibility shims with deprecation warnings: - app/services/content_page_service.py -> app.modules.cms.services - app/exceptions/content_page.py -> app.modules.cms.exceptions Note: SQLAlchemy models remain in models/database/ as the canonical location to avoid circular imports at startup time. Module model packages re-export from the canonical location. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
# app/modules/cms/definition.py
|
|
"""
|
|
CMS module definition.
|
|
|
|
Defines the CMS module including its features, menu items,
|
|
route configurations, and self-contained component paths.
|
|
|
|
This is a self-contained module with:
|
|
- Services: app.modules.cms.services
|
|
- Models: app.modules.cms.models
|
|
- Exceptions: app.modules.cms.exceptions
|
|
|
|
Templates remain in core (app/templates/admin/) for now due to
|
|
admin/base.html inheritance dependency.
|
|
"""
|
|
|
|
from app.modules.base import ModuleDefinition
|
|
from models.database.admin_menu_config import FrontendType
|
|
|
|
|
|
def _get_admin_router():
|
|
"""Lazy import of admin router to avoid circular imports."""
|
|
from app.modules.cms.routes.admin import admin_router
|
|
|
|
return admin_router
|
|
|
|
|
|
def _get_vendor_router():
|
|
"""Lazy import of vendor router to avoid circular imports."""
|
|
from app.modules.cms.routes.vendor import vendor_router
|
|
|
|
return vendor_router
|
|
|
|
|
|
# CMS module definition - Self-contained module (pilot)
|
|
cms_module = ModuleDefinition(
|
|
code="cms",
|
|
name="Content Management",
|
|
description="Content pages, media library, and vendor themes.",
|
|
features=[
|
|
"cms_basic", # Basic page editing
|
|
"cms_custom_pages", # Custom page creation
|
|
"cms_unlimited_pages", # No page limit
|
|
"cms_templates", # Page templates
|
|
"cms_seo", # SEO tools
|
|
"media_library", # Media file management
|
|
],
|
|
menu_items={
|
|
FrontendType.ADMIN: [
|
|
"content-pages", # Platform content pages
|
|
"vendor-themes", # Theme management
|
|
],
|
|
FrontendType.VENDOR: [
|
|
"content-pages", # Vendor content pages
|
|
"media", # Media library
|
|
],
|
|
},
|
|
is_core=False,
|
|
# Self-contained module configuration
|
|
is_self_contained=True,
|
|
services_path="app.modules.cms.services",
|
|
models_path="app.modules.cms.models",
|
|
exceptions_path="app.modules.cms.exceptions",
|
|
# Templates remain in core for now (admin/content-pages*.html)
|
|
templates_path=None,
|
|
)
|
|
|
|
|
|
def get_cms_module_with_routers() -> ModuleDefinition:
|
|
"""
|
|
Get CMS module with routers attached.
|
|
|
|
This function attaches the routers lazily to avoid circular imports
|
|
during module initialization.
|
|
"""
|
|
cms_module.admin_router = _get_admin_router()
|
|
cms_module.vendor_router = _get_vendor_router()
|
|
return cms_module
|
|
|
|
|
|
__all__ = ["cms_module", "get_cms_module_with_routers"]
|