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>
This commit is contained in:
2026-01-26 22:42:46 +01:00
parent 8ff9c39845
commit ec4ec045fc
40 changed files with 878 additions and 695 deletions

33
main.py
View File

@@ -63,6 +63,10 @@ from app.exceptions.handler import setup_exception_handlers
# Import page routers
from app.routes import admin_pages, platform_pages, shop_pages, vendor_pages
# Import CMS module page routers (self-contained module)
from app.modules.cms.routes.pages import admin_router as cms_admin_pages
from app.modules.cms.routes.pages import vendor_router as cms_vendor_pages
from app.utils.i18n import get_jinja2_globals
from middleware.context import ContextMiddleware
from middleware.language import LanguageMiddleware
@@ -180,6 +184,19 @@ if STATIC_DIR.exists():
else:
logger.warning(f"Static directory not found at {STATIC_DIR}")
# Mount module static files (self-contained modules)
MODULES_DIR = BASE_DIR / "app" / "modules"
if MODULES_DIR.exists():
for module_dir in sorted(MODULES_DIR.iterdir()):
if not module_dir.is_dir():
continue
module_static = module_dir / "static"
if module_static.exists():
module_name = module_dir.name
mount_path = f"/static/modules/{module_name}"
app.mount(mount_path, StaticFiles(directory=str(module_static)), name=f"{module_name}_static")
logger.info(f"Mounted module static files: {mount_path} -> {module_static}")
# Mount uploads directory for user-uploaded media files
UPLOADS_DIR = BASE_DIR / "uploads"
if UPLOADS_DIR.exists():
@@ -301,6 +318,13 @@ app.include_router(
admin_pages.router, prefix="/admin", tags=["admin-pages"], include_in_schema=False
)
# CMS module admin pages (self-contained module)
# NOTE: These routes are specific (/content-pages/*) so they won't conflict
logger.info("Registering CMS admin page routes: /admin/content-pages/*")
app.include_router(
cms_admin_pages, prefix="/admin", tags=["cms-admin-pages"], include_in_schema=False
)
# Vendor management pages (dashboard, products, orders, etc.)
logger.info("Registering vendor page routes: /vendor/{code}/*")
app.include_router(
@@ -310,6 +334,13 @@ app.include_router(
include_in_schema=False,
)
# CMS module vendor pages (self-contained module)
# NOTE: Includes catch-all /{vendor_code}/{slug} - must be registered AFTER vendor_pages
logger.info("Registering CMS vendor page routes: /vendor/{code}/content-pages/*")
app.include_router(
cms_vendor_pages, prefix="/vendor", tags=["cms-vendor-pages"], include_in_schema=False
)
# Customer shop pages - Register at TWO prefixes:
# 1. /shop/* (for subdomain/custom domain modes)
# 2. /vendors/{code}/shop/* (for path-based development mode)
@@ -345,7 +376,7 @@ async def vendor_root_path(
raise HTTPException(status_code=404, detail=f"Vendor '{vendor_code}' not found")
from app.routes.shop_pages import get_shop_context
from app.services.content_page_service import content_page_service
from app.modules.cms.services import content_page_service
# Get platform_id (use platform from context or default to 1 for OMS)
platform_id = platform.id if platform else 1