Files
orion/app/modules/cms/definition.py
Samir Boulahtit ec4ec045fc feat: complete CMS as fully autonomous self-contained module
Transform CMS from a thin wrapper into a fully self-contained module with
all code living within app/modules/cms/:

Module Structure:
- models/: ContentPage model (canonical location with dynamic discovery)
- schemas/: Pydantic schemas for API validation
- services/: ContentPageService business logic
- exceptions/: Module-specific exceptions
- routes/api/: REST API endpoints (admin, vendor, shop)
- routes/pages/: HTML page routes (admin, vendor)
- templates/cms/: Jinja2 templates (namespaced)
- static/: JavaScript files (admin/vendor)
- locales/: i18n translations (en, fr, de, lb)

Key Changes:
- Move ContentPage model to module with dynamic model discovery
- Create Pydantic schemas package for request/response validation
- Extract API routes from app/api/v1/*/ to module
- Extract page routes from admin_pages.py/vendor_pages.py to module
- Move static JS files to module with dedicated mount point
- Update templates to use cms_static for module assets
- Add module static file mounting in main.py
- Delete old scattered files (no shims - hard errors on old imports)

This establishes the pattern for migrating other modules to be
fully autonomous and independently deployable.

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

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: app.modules.cms.templates (namespaced as cms/)
"""
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",
# Module templates (namespaced as cms/admin/*.html and cms/vendor/*.html)
templates_path="templates",
# Module-specific translations (accessible via cms.* keys)
locales_path="locales",
)
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"]