Phase 1-3 of decoupling plan: - Shared DB, models, infrastructure, browser, config, utils - Event infrastructure (domain_events outbox, bus, processor) - Structured logging - Generic container concept (container_type/container_id) - Alembic migrations for all schema changes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
"""HTMX utilities for detecting and handling HTMX requests."""
|
|
|
|
from quart import request
|
|
|
|
|
|
def is_htmx_request() -> bool:
|
|
"""
|
|
Check if the current request is an HTMX request.
|
|
|
|
Returns:
|
|
bool: True if HX-Request header is present and true
|
|
"""
|
|
return request.headers.get("HX-Request", "").lower() == "true"
|
|
|
|
|
|
def get_htmx_target() -> str | None:
|
|
"""
|
|
Get the target element ID from HTMX request headers.
|
|
|
|
Returns:
|
|
str | None: Target element ID or None
|
|
"""
|
|
return request.headers.get("HX-Target")
|
|
|
|
|
|
def get_htmx_trigger() -> str | None:
|
|
"""
|
|
Get the trigger element ID from HTMX request headers.
|
|
|
|
Returns:
|
|
str | None: Trigger element ID or None
|
|
"""
|
|
return request.headers.get("HX-Trigger")
|
|
|
|
|
|
def should_return_fragment() -> bool:
|
|
"""
|
|
Determine if we should return a fragment vs full page.
|
|
|
|
For HTMX requests, return fragment.
|
|
For normal requests, return full page.
|
|
|
|
Returns:
|
|
bool: True if fragment should be returned
|
|
"""
|
|
return is_htmx_request()
|