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:
@@ -1,18 +1,2 @@
|
||||
# app/modules/billing/routes/pages/__init__.py
|
||||
"""
|
||||
Billing module page routes (HTML rendering).
|
||||
|
||||
Provides Jinja2 template rendering for billing management:
|
||||
- Admin pages: Subscription tiers, subscriptions list, billing history
|
||||
- Vendor pages: Billing dashboard, invoices
|
||||
|
||||
Note: These routes are placeholders. The actual page rendering
|
||||
is currently handled by routes in app/api/v1/ and can be migrated here.
|
||||
"""
|
||||
|
||||
__all__ = []
|
||||
|
||||
|
||||
def __getattr__(name: str):
|
||||
"""Lazy import routers to avoid circular dependencies."""
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
"""Billing module page routes."""
|
||||
|
||||
80
app/modules/billing/routes/pages/admin.py
Normal file
80
app/modules/billing/routes/pages/admin.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# app/modules/billing/routes/pages/admin.py
|
||||
"""
|
||||
Billing Admin Page Routes (HTML rendering).
|
||||
|
||||
Admin pages for billing and subscription management:
|
||||
- Subscription tiers
|
||||
- Subscriptions list
|
||||
- Billing history
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, 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()
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# BILLING & SUBSCRIPTIONS ROUTES
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get("/subscription-tiers", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def admin_subscription_tiers_page(
|
||||
request: Request,
|
||||
current_user: User = Depends(
|
||||
require_menu_access("subscription-tiers", FrontendType.ADMIN)
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render subscription tiers management page.
|
||||
Shows all subscription tiers with their limits and pricing.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"billing/admin/subscription-tiers.html",
|
||||
get_admin_context(request, current_user),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/subscriptions", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def admin_subscriptions_page(
|
||||
request: Request,
|
||||
current_user: User = Depends(
|
||||
require_menu_access("subscriptions", FrontendType.ADMIN)
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render vendor subscriptions management page.
|
||||
Shows all vendor subscriptions with status and usage.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"billing/admin/subscriptions.html",
|
||||
get_admin_context(request, current_user),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/billing-history", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def admin_billing_history_page(
|
||||
request: Request,
|
||||
current_user: User = Depends(
|
||||
require_menu_access("billing-history", FrontendType.ADMIN)
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Render billing history page.
|
||||
Shows invoices and payments across all vendors.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"billing/admin/billing-history.html",
|
||||
get_admin_context(request, current_user),
|
||||
)
|
||||
121
app/modules/billing/routes/pages/public.py
Normal file
121
app/modules/billing/routes/pages/public.py
Normal file
@@ -0,0 +1,121 @@
|
||||
# app/modules/billing/routes/pages/public.py
|
||||
"""
|
||||
Billing Public Page Routes (HTML rendering).
|
||||
|
||||
Public (unauthenticated) pages for pricing and signup:
|
||||
- Pricing page
|
||||
- Signup wizard
|
||||
- Signup success
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.modules.billing.models import TIER_LIMITS, TierCode
|
||||
from app.modules.core.utils.page_context import get_public_context
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def _get_tiers_data() -> list[dict]:
|
||||
"""Build tier data for display in templates."""
|
||||
tiers = []
|
||||
for tier_code, limits in TIER_LIMITS.items():
|
||||
tiers.append(
|
||||
{
|
||||
"code": tier_code.value,
|
||||
"name": limits["name"],
|
||||
"price_monthly": limits["price_monthly_cents"] / 100,
|
||||
"price_annual": (limits["price_annual_cents"] / 100)
|
||||
if limits.get("price_annual_cents")
|
||||
else None,
|
||||
"orders_per_month": limits.get("orders_per_month"),
|
||||
"products_limit": limits.get("products_limit"),
|
||||
"team_members": limits.get("team_members"),
|
||||
"order_history_months": limits.get("order_history_months"),
|
||||
"features": limits.get("features", []),
|
||||
"is_popular": tier_code == TierCode.PROFESSIONAL,
|
||||
"is_enterprise": tier_code == TierCode.ENTERPRISE,
|
||||
}
|
||||
)
|
||||
return tiers
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PRICING PAGE
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get("/pricing", response_class=HTMLResponse, name="platform_pricing")
|
||||
async def pricing_page(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Standalone pricing page with detailed tier comparison.
|
||||
"""
|
||||
context = get_public_context(request, db)
|
||||
context["tiers"] = _get_tiers_data()
|
||||
context["page_title"] = "Pricing"
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"billing/public/pricing.html",
|
||||
context,
|
||||
)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# SIGNUP WIZARD
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get("/signup", response_class=HTMLResponse, name="platform_signup")
|
||||
async def signup_page(
|
||||
request: Request,
|
||||
tier: str | None = None,
|
||||
annual: bool = False,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Multi-step signup wizard.
|
||||
|
||||
Query params:
|
||||
- tier: Pre-selected tier code
|
||||
- annual: Pre-select annual billing
|
||||
"""
|
||||
context = get_public_context(request, db)
|
||||
context["page_title"] = "Start Your Free Trial"
|
||||
context["selected_tier"] = tier
|
||||
context["is_annual"] = annual
|
||||
context["tiers"] = _get_tiers_data()
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"billing/public/signup.html",
|
||||
context,
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/signup/success", response_class=HTMLResponse, name="platform_signup_success"
|
||||
)
|
||||
async def signup_success_page(
|
||||
request: Request,
|
||||
vendor_code: str | None = None,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
Signup success page.
|
||||
|
||||
Shown after successful account creation.
|
||||
"""
|
||||
context = get_public_context(request, db)
|
||||
context["page_title"] = "Welcome to Wizamart!"
|
||||
context["vendor_code"] = vendor_code
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"billing/public/signup-success.html",
|
||||
context,
|
||||
)
|
||||
62
app/modules/billing/routes/pages/vendor.py
Normal file
62
app/modules/billing/routes/pages/vendor.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# app/modules/billing/routes/pages/vendor.py
|
||||
"""
|
||||
Billing Vendor Page Routes (HTML rendering).
|
||||
|
||||
Vendor pages for billing management:
|
||||
- Billing dashboard
|
||||
- Invoices
|
||||
"""
|
||||
|
||||
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()
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# BILLING ROUTES
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@router.get(
|
||||
"/{vendor_code}/billing", response_class=HTMLResponse, include_in_schema=False
|
||||
)
|
||||
async def vendor_billing_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 billing and subscription management page.
|
||||
JavaScript loads subscription status, tiers, and invoices via API.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"billing/vendor/billing.html",
|
||||
get_vendor_context(request, db, current_user, vendor_code),
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/{vendor_code}/invoices", response_class=HTMLResponse, include_in_schema=False
|
||||
)
|
||||
async def vendor_invoices_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 invoices management page.
|
||||
JavaScript loads invoices via API.
|
||||
"""
|
||||
return templates.TemplateResponse(
|
||||
"orders/vendor/invoices.html",
|
||||
get_vendor_context(request, db, current_user, vendor_code),
|
||||
)
|
||||
Reference in New Issue
Block a user