Files
orion/app/modules/analytics/routes/pages/store.py
Samir Boulahtit 3a264c0a39
Some checks failed
CI / ruff (push) Failing after 7s
CI / pytest (push) Failing after 1s
CI / architecture (push) Failing after 8s
CI / dependency-scanning (push) Successful in 26s
CI / audit (push) Successful in 9s
CI / docs (push) Has been skipped
fix(lint): restore noqa directives and register custom codes with ruff
Reverts the noqa: removal — the architecture validators (SVC-006,
SEC-034, MOD-004, API-007) use these to skip known-safe violations.
Added ruff lint.external config so ruff treats them as valid codes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 23:21:27 +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, # noqa: 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),
)