refactor: centralize locale resolution through PlatformSettingsService

Remove hardcoded locale fallbacks from templates and ensure all routes
use the proper resolution chain (AdminSetting → Config → Default).

Changes:
- Add get_vendor_context() helper to vendor_pages.py mirroring shop pattern
- Update all vendor routes to use get_vendor_context() with db session
- Update shop routes to pass db session for locale resolution
- Remove hardcoded fallbacks from shop/base.html and vendor/base.html
- Templates now receive pre-resolved locale values from routes

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-03 11:12:06 +01:00
parent 214e3997b0
commit 3715493e47
4 changed files with 162 additions and 130 deletions

View File

@@ -240,7 +240,9 @@ async def shop_products_page(request: Request, db: Session = Depends(get_db)):
"/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")
request: Request,
product_id: int = Path(..., description="Product ID"),
db: Session = Depends(get_db),
):
"""
Render product detail page.
@@ -256,7 +258,7 @@ async def shop_product_detail_page(
)
return templates.TemplateResponse(
"shop/product.html", get_shop_context(request, product_id=product_id)
"shop/product.html", get_shop_context(request, db=db, product_id=product_id)
)
@@ -264,7 +266,9 @@ async def shop_product_detail_page(
"/categories/{category_slug}", response_class=HTMLResponse, include_in_schema=False
)
async def shop_category_page(
request: Request, category_slug: str = Path(..., description="Category slug")
request: Request,
category_slug: str = Path(..., description="Category slug"),
db: Session = Depends(get_db),
):
"""
Render category products page.
@@ -280,12 +284,12 @@ async def shop_category_page(
)
return templates.TemplateResponse(
"shop/category.html", get_shop_context(request, category_slug=category_slug)
"shop/category.html", get_shop_context(request, db=db, category_slug=category_slug)
)
@router.get("/cart", response_class=HTMLResponse, include_in_schema=False)
async def shop_cart_page(request: Request):
async def shop_cart_page(request: Request, db: Session = Depends(get_db)):
"""
Render shopping cart page.
Shows cart items and allows quantity updates.
@@ -299,11 +303,11 @@ async def shop_cart_page(request: Request):
},
)
return templates.TemplateResponse("shop/cart.html", get_shop_context(request))
return templates.TemplateResponse("shop/cart.html", get_shop_context(request, db=db))
@router.get("/checkout", response_class=HTMLResponse, include_in_schema=False)
async def shop_checkout_page(request: Request):
async def shop_checkout_page(request: Request, db: Session = Depends(get_db)):
"""
Render checkout page.
Handles shipping, payment, and order confirmation.
@@ -317,11 +321,11 @@ async def shop_checkout_page(request: Request):
},
)
return templates.TemplateResponse("shop/checkout.html", get_shop_context(request))
return templates.TemplateResponse("shop/checkout.html", get_shop_context(request, db=db))
@router.get("/search", response_class=HTMLResponse, include_in_schema=False)
async def shop_search_page(request: Request):
async def shop_search_page(request: Request, db: Session = Depends(get_db)):
"""
Render search results page.
Shows products matching search query.
@@ -335,7 +339,7 @@ async def shop_search_page(request: Request):
},
)
return templates.TemplateResponse("shop/search.html", get_shop_context(request))
return templates.TemplateResponse("shop/search.html", get_shop_context(request, db=db))
# ============================================================================
@@ -344,7 +348,7 @@ async def shop_search_page(request: Request):
@router.get("/account/register", response_class=HTMLResponse, include_in_schema=False)
async def shop_register_page(request: Request):
async def shop_register_page(request: Request, db: Session = Depends(get_db)):
"""
Render customer registration page.
No authentication required.
@@ -359,12 +363,12 @@ async def shop_register_page(request: Request):
)
return templates.TemplateResponse(
"shop/account/register.html", get_shop_context(request)
"shop/account/register.html", get_shop_context(request, db=db)
)
@router.get("/account/login", response_class=HTMLResponse, include_in_schema=False)
async def shop_login_page(request: Request):
async def shop_login_page(request: Request, db: Session = Depends(get_db)):
"""
Render customer login page.
No authentication required.
@@ -379,14 +383,14 @@ async def shop_login_page(request: Request):
)
return templates.TemplateResponse(
"shop/account/login.html", get_shop_context(request)
"shop/account/login.html", get_shop_context(request, db=db)
)
@router.get(
"/account/forgot-password", response_class=HTMLResponse, include_in_schema=False
)
async def shop_forgot_password_page(request: Request):
async def shop_forgot_password_page(request: Request, db: Session = Depends(get_db)):
"""
Render forgot password page.
Allows customers to reset their password.
@@ -401,7 +405,7 @@ async def shop_forgot_password_page(request: Request):
)
return templates.TemplateResponse(
"shop/account/forgot-password.html", get_shop_context(request)
"shop/account/forgot-password.html", get_shop_context(request, db=db)
)
@@ -752,7 +756,7 @@ async def generic_content_page(
)
return templates.TemplateResponse(
"shop/content-page.html", get_shop_context(request, page=page)
"shop/content-page.html", get_shop_context(request, db=db, page=page)
)