Files
orion/app/modules/analytics/routes/pages/store.py
Samir Boulahtit 79c985ee39
Some checks failed
CI / ruff (push) Failing after 7s
CI / pytest (push) Failing after 0s
CI / architecture (push) Failing after 8s
CI / dependency-scanning (push) Successful in 26s
CI / audit (push) Successful in 8s
CI / docs (push) Has been skipped
fix(lint): use plain comments for architecture validator codes
Replace # noqa: SVC-006 with # SVC-006 to avoid ruff warnings about
unknown codes. Updated architecture validators to match the new format
by checking for the code string directly instead of the noqa: prefix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 23:24:57 +01:00

92 lines
2.6 KiB
Python

# app/modules/analytics/routes/pages/store.py
"""
Analytics Store Page Routes (HTML rendering).
Store pages for analytics dashboard.
"""
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_current_store_from_cookie_or_header, get_db
from app.modules.core.services.platform_settings_service import (
platform_settings_service, # MOD-004 - shared platform service
)
from app.modules.tenancy.models import Store, User
from app.templates_config import templates
logger = logging.getLogger(__name__)
router = APIRouter()
# ============================================================================
# HELPER: Build Store Dashboard Context
# ============================================================================
def get_store_context(
request: Request,
db: Session,
current_user: User,
store_code: str,
**extra_context,
) -> dict:
"""
Build template context for store dashboard pages.
Resolves locale/currency using the platform settings service with
store override support.
"""
# Load store from database
store = db.query(Store).filter(Store.subdomain == store_code).first()
# Get platform defaults
platform_config = platform_settings_service.get_storefront_config(db)
# Resolve with store override
storefront_locale = platform_config["locale"]
storefront_currency = platform_config["currency"]
if store and store.storefront_locale:
storefront_locale = store.storefront_locale
context = {
"request": request,
"user": current_user,
"store": store,
"store_code": store_code,
"storefront_locale": storefront_locale,
"storefront_currency": storefront_currency,
**extra_context,
}
return context
# ============================================================================
# ANALYTICS PAGE
# ============================================================================
@router.get(
"/{store_code}/analytics", response_class=HTMLResponse, include_in_schema=False
)
async def store_analytics_page(
request: Request,
store_code: str = Path(..., description="Store code"),
current_user: User = Depends(get_current_store_from_cookie_or_header),
db: Session = Depends(get_db),
):
"""
Render analytics and reports page.
JavaScript loads analytics data via API.
"""
return templates.TemplateResponse(
"analytics/store/analytics.html",
get_store_context(request, db, current_user, store_code),
)