refactor: migrate templates and static files to self-contained modules
Templates Migration: - Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.) - Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.) - Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms) - Migrate public templates to modules (billing, marketplace, cms) - Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/) - Migrate letzshop partials to marketplace module Static Files Migration: - Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file) - Migrate vendor JS to modules: tenancy (4 files), core (2 files) - Migrate shared JS: vendor-selector.js to core, media-picker.js to cms - Migrate storefront JS: storefront-layout.js to core - Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/) - Update all template references to use module_static paths Naming Consistency: - Rename static/platform/ to static/public/ - Rename app/templates/platform/ to app/templates/public/ - Update all extends and static references Documentation: - Update module-system.md with shared templates documentation - Update frontend-structure.md with new module JS organization Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,8 +17,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_api, require_module_access
|
||||
from app.core.database import get_db
|
||||
from app.services.subscription_service import subscription_service
|
||||
from app.services.vendor_product_service import vendor_product_service
|
||||
from app.modules.billing.services.subscription_service import subscription_service
|
||||
from app.modules.catalog.services.vendor_product_service import vendor_product_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.catalog.schemas import (
|
||||
CatalogVendor,
|
||||
|
||||
@@ -109,7 +109,7 @@ def get_product_details(
|
||||
|
||||
# Check if product is active
|
||||
if not product.is_active:
|
||||
from app.exceptions import ProductNotActiveException
|
||||
from app.modules.catalog.exceptions import ProductNotActiveException
|
||||
|
||||
raise ProductNotActiveException(str(product_id))
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_vendor_api, require_module_access
|
||||
from app.core.database import get_db
|
||||
from app.services.product_service import product_service
|
||||
from app.services.subscription_service import subscription_service
|
||||
from app.services.vendor_product_service import vendor_product_service
|
||||
from app.modules.catalog.services.product_service import product_service
|
||||
from app.modules.billing.services.subscription_service import subscription_service
|
||||
from app.modules.catalog.services.vendor_product_service import vendor_product_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.catalog.schemas import (
|
||||
ProductCreate,
|
||||
|
||||
2
app/modules/catalog/routes/pages/__init__.py
Normal file
2
app/modules/catalog/routes/pages/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# app/modules/catalog/routes/pages/__init__.py
|
||||
"""Catalog module page routes."""
|
||||
110
app/modules/catalog/routes/pages/admin.py
Normal file
110
app/modules/catalog/routes/pages/admin.py
Normal file
@@ -0,0 +1,110 @@
|
||||
# app/modules/catalog/routes/pages/admin.py
|
||||
"""
|
||||
Catalog Admin Page Routes (HTML rendering).
|
||||
|
||||
Admin pages for vendor product catalog management:
|
||||
- Vendor products list
|
||||
- Vendor product create
|
||||
- Vendor product detail/edit
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, Path, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_db, require_menu_access
|
||||
from app.modules.core.utils.page_context import get_admin_context
|
||||
from app.templates_config import templates
|
||||
from models.database.admin_menu_config import FrontendType
|
||||
from models.database.user import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# VENDOR PRODUCT CATALOG ROUTES
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get("/vendor-products", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def admin_vendor_products_page(
|
||||
request: Request,
|
||||
current_user: User = Depends(
|
||||
require_menu_access("vendor-products", FrontendType.ADMIN)
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render vendor products catalog page.
|
||||
Browse vendor-specific product catalogs with override capability.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"catalog/admin/vendor-products.html",
|
||||
get_admin_context(request, current_user),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/vendor-products/create", response_class=HTMLResponse, include_in_schema=False
|
||||
)
|
||||
async def admin_vendor_product_create_page(
|
||||
request: Request,
|
||||
current_user: User = Depends(
|
||||
require_menu_access("vendor-products", FrontendType.ADMIN)
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render vendor product create page.
|
||||
Create a new vendor product entry.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"catalog/admin/vendor-product-create.html",
|
||||
get_admin_context(request, current_user),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/vendor-products/{product_id}",
|
||||
response_class=HTMLResponse,
|
||||
include_in_schema=False,
|
||||
)
|
||||
async def admin_vendor_product_detail_page(
|
||||
request: Request,
|
||||
product_id: int = Path(..., description="Vendor Product ID"),
|
||||
current_user: User = Depends(
|
||||
require_menu_access("vendor-products", FrontendType.ADMIN)
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render vendor product detail page.
|
||||
Shows full product information with vendor-specific overrides.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"catalog/admin/vendor-product-detail.html",
|
||||
get_admin_context(request, current_user, product_id=product_id),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/vendor-products/{product_id}/edit",
|
||||
response_class=HTMLResponse,
|
||||
include_in_schema=False,
|
||||
)
|
||||
async def admin_vendor_product_edit_page(
|
||||
request: Request,
|
||||
product_id: int = Path(..., description="Vendor Product ID"),
|
||||
current_user: User = Depends(
|
||||
require_menu_access("vendor-products", FrontendType.ADMIN)
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render vendor product edit page.
|
||||
Edit vendor product information and overrides.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"catalog/admin/vendor-product-edit.html",
|
||||
get_admin_context(request, current_user, product_id=product_id),
|
||||
)
|
||||
171
app/modules/catalog/routes/pages/storefront.py
Normal file
171
app/modules/catalog/routes/pages/storefront.py
Normal file
@@ -0,0 +1,171 @@
|
||||
# app/modules/catalog/routes/pages/storefront.py
|
||||
"""
|
||||
Catalog Storefront Page Routes (HTML rendering).
|
||||
|
||||
Storefront (customer shop) pages for catalog browsing:
|
||||
- Shop homepage / product catalog
|
||||
- Product list
|
||||
- Product detail
|
||||
- Category products
|
||||
- Search results
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Depends, Path, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_db
|
||||
from app.modules.core.utils.page_context import get_storefront_context
|
||||
from app.templates_config import templates
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PUBLIC SHOP ROUTES (No Authentication Required)
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse, include_in_schema=False)
|
||||
@router.get("/products", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def shop_products_page(request: Request, db: Session = Depends(get_db)):
|
||||
"""
|
||||
Render shop homepage / product catalog.
|
||||
Shows featured products and categories.
|
||||
"""
|
||||
logger.debug(
|
||||
"[STOREFRONT] shop_products_page REACHED",
|
||||
extra={
|
||||
"path": request.url.path,
|
||||
"vendor": getattr(request.state, "vendor", "NOT SET"),
|
||||
"context": getattr(request.state, "context_type", "NOT SET"),
|
||||
},
|
||||
)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"catalog/storefront/products.html", get_storefront_context(request, db=db)
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/products/{product_id}", response_class=HTMLResponse, include_in_schema=False
|
||||
)
|
||||
async def shop_product_detail_page(
|
||||
request: Request,
|
||||
product_id: int = Path(..., description="Product ID"),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render product detail page.
|
||||
Shows product information, images, reviews, and buy options.
|
||||
"""
|
||||
logger.debug(
|
||||
"[STOREFRONT] shop_product_detail_page REACHED",
|
||||
extra={
|
||||
"path": request.url.path,
|
||||
"product_id": product_id,
|
||||
"vendor": getattr(request.state, "vendor", "NOT SET"),
|
||||
"context": getattr(request.state, "context_type", "NOT SET"),
|
||||
},
|
||||
)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"catalog/storefront/product.html",
|
||||
get_storefront_context(request, db=db, product_id=product_id),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/categories/{category_slug}",
|
||||
response_class=HTMLResponse,
|
||||
include_in_schema=False,
|
||||
)
|
||||
async def shop_category_page(
|
||||
request: Request,
|
||||
category_slug: str = Path(..., description="Category slug"),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render category products page.
|
||||
Shows all products in a specific category.
|
||||
"""
|
||||
logger.debug(
|
||||
"[STOREFRONT] shop_category_page REACHED",
|
||||
extra={
|
||||
"path": request.url.path,
|
||||
"category_slug": category_slug,
|
||||
"vendor": getattr(request.state, "vendor", "NOT SET"),
|
||||
"context": getattr(request.state, "context_type", "NOT SET"),
|
||||
},
|
||||
)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"catalog/storefront/category.html",
|
||||
get_storefront_context(request, db=db, category_slug=category_slug),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/search", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def shop_search_page(request: Request, db: Session = Depends(get_db)):
|
||||
"""
|
||||
Render search results page.
|
||||
Shows products matching search query.
|
||||
"""
|
||||
logger.debug(
|
||||
"[STOREFRONT] shop_search_page REACHED",
|
||||
extra={
|
||||
"path": request.url.path,
|
||||
"vendor": getattr(request.state, "vendor", "NOT SET"),
|
||||
"context": getattr(request.state, "context_type", "NOT SET"),
|
||||
},
|
||||
)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"catalog/storefront/search.html", get_storefront_context(request, db=db)
|
||||
)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# CUSTOMER ACCOUNT - WISHLIST
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get(
|
||||
"/account/wishlist", response_class=HTMLResponse, include_in_schema=False
|
||||
)
|
||||
async def shop_wishlist_page(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render customer wishlist page.
|
||||
View and manage saved products.
|
||||
Requires customer authentication (handled by middleware/template).
|
||||
"""
|
||||
from app.api.deps import get_current_customer_from_cookie_or_header
|
||||
|
||||
# Get customer if authenticated
|
||||
try:
|
||||
current_customer = await get_current_customer_from_cookie_or_header(
|
||||
request=request, db=db
|
||||
)
|
||||
except Exception:
|
||||
current_customer = None
|
||||
|
||||
logger.debug(
|
||||
"[STOREFRONT] shop_wishlist_page REACHED",
|
||||
extra={
|
||||
"path": request.url.path,
|
||||
"vendor": getattr(request.state, "vendor", "NOT SET"),
|
||||
"context": getattr(request.state, "context_type", "NOT SET"),
|
||||
},
|
||||
)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"catalog/storefront/wishlist.html",
|
||||
get_storefront_context(request, db=db, user=current_customer),
|
||||
)
|
||||
64
app/modules/catalog/routes/pages/vendor.py
Normal file
64
app/modules/catalog/routes/pages/vendor.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# app/modules/catalog/routes/pages/vendor.py
|
||||
"""
|
||||
Catalog Vendor Page Routes (HTML rendering).
|
||||
|
||||
Vendor pages for product management:
|
||||
- Products list
|
||||
- Product create
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, Path, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_vendor_from_cookie_or_header, get_db
|
||||
from app.modules.core.utils.page_context import get_vendor_context
|
||||
from app.templates_config import templates
|
||||
from models.database.user import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PRODUCT MANAGEMENT
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get(
|
||||
"/{vendor_code}/products", response_class=HTMLResponse, include_in_schema=False
|
||||
)
|
||||
async def vendor_products_page(
|
||||
request: Request,
|
||||
vendor_code: str = Path(..., description="Vendor code"),
|
||||
current_user: User = Depends(get_current_vendor_from_cookie_or_header),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render products management page.
|
||||
JavaScript loads product list via API.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"catalog/vendor/products.html",
|
||||
get_vendor_context(request, db, current_user, vendor_code),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/{vendor_code}/products/create",
|
||||
response_class=HTMLResponse,
|
||||
include_in_schema=False,
|
||||
)
|
||||
async def vendor_product_create_page(
|
||||
request: Request,
|
||||
vendor_code: str = Path(..., description="Vendor code"),
|
||||
current_user: User = Depends(get_current_vendor_from_cookie_or_header),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render product creation page.
|
||||
JavaScript handles form submission via API.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"catalog/vendor/product-create.html",
|
||||
get_vendor_context(request, db, current_user, vendor_code),
|
||||
)
|
||||
Reference in New Issue
Block a user