feat: integrate CMS content pages with platform homepage

Update platform homepage to dynamically load header and footer navigation
from the CMS content pages instead of hardcoded values:

- Import content_page_service in platform_pages.py
- Update get_platform_context() to fetch pages with show_in_header=True
  and show_in_footer=True from the database
- Add generic /{slug} route to serve CMS content pages (about, contact,
  faq, privacy, terms, etc.)
- Platform pages use vendor_id=None for platform-wide defaults

Pages can be managed via Admin > Content Pages with:
- show_in_header: Display in header navigation
- show_in_footer: Display in footer quick links
- display_order: Control menu ordering

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-28 19:54:14 +01:00
parent c1bfe07c43
commit c4ca57e9a0

View File

@@ -9,13 +9,14 @@ Letzshop vendor finder, and signup wizard.
import logging
from pathlib import Path
from fastapi import APIRouter, Depends, Request
from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session
from app.core.config import settings
from app.core.database import get_db
from app.services.content_page_service import content_page_service
from app.utils.i18n import get_jinja2_globals
router = APIRouter()
@@ -34,7 +35,6 @@ def get_platform_context(request: Request, db: Session) -> dict:
# Get translation function
i18n_globals = get_jinja2_globals(language)
t = i18n_globals["t"]
context = {
"request": request,
@@ -47,12 +47,25 @@ def get_platform_context(request: Request, db: Session) -> dict:
# Add i18n globals (_, t, current_language, SUPPORTED_LANGUAGES, etc.)
context.update(i18n_globals)
# Add footer CMS pages
context["footer_pages"] = [
{"slug": "about", "title": t("platform.footer.about")},
{"slug": "faq", "title": t("platform.footer.faq")},
{"slug": "contact", "title": t("platform.footer.contact_us")},
]
# Load CMS pages for header and footer navigation
header_pages = []
footer_pages = []
try:
# Platform pages have vendor_id=None
header_pages = content_page_service.list_pages_for_vendor(
db, vendor_id=None, header_only=True, include_unpublished=False
)
footer_pages = content_page_service.list_pages_for_vendor(
db, vendor_id=None, footer_only=True, include_unpublished=False
)
logger.debug(
f"Loaded CMS pages: {len(header_pages)} header, {len(footer_pages)} footer"
)
except Exception as e:
logger.error(f"Failed to load CMS navigation pages: {e}")
context["header_pages"] = header_pages
context["footer_pages"] = footer_pages
return context
@@ -271,3 +284,39 @@ async def signup_success_page(
"platform/signup-success.html",
context,
)
# =============================================================================
# Generic Content Pages (CMS)
# =============================================================================
# IMPORTANT: This route must be LAST as it catches all /{slug} URLs
@router.get("/{slug}", response_class=HTMLResponse, name="platform_content_page")
async def content_page(
request: Request,
slug: str,
db: Session = Depends(get_db),
):
"""
Serve CMS content pages (about, contact, faq, privacy, terms, etc.).
This is a catch-all route for dynamic content pages managed via the admin CMS.
Platform pages have vendor_id=None.
"""
# Load content page from database (platform defaults only)
page = content_page_service.get_page_for_vendor(
db, slug=slug, vendor_id=None, include_unpublished=False
)
if not page:
raise HTTPException(status_code=404, detail=f"Page not found: {slug}")
context = get_platform_context(request, db)
context["page"] = page
context["page_title"] = page.title
return templates.TemplateResponse(
"platform/content-page.html",
context,
)