From c4ca57e9a028de0c5ff196511463c525f1f2b3c0 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sun, 28 Dec 2025 19:54:14 +0100 Subject: [PATCH] feat: integrate CMS content pages with platform homepage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/routes/platform_pages.py | 65 +++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/app/routes/platform_pages.py b/app/routes/platform_pages.py index d816697a..bca83740 100644 --- a/app/routes/platform_pages.py +++ b/app/routes/platform_pages.py @@ -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, + )