Coverage for src / lexigram / contracts / admin / page_handler.py: 100%
8 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
1"""Management page handler protocols for lexigram-admin contributors.
3``handle_action`` is duck-typed (not part of the protocol) so that
4handlers with only ``handle`` satisfy ``isinstance(handler, ManagementPageHandler)``.
5The framework uses ``hasattr(handler, "handle_action")`` to discover action support.
6"""
8from __future__ import annotations
10from typing import Any, Protocol, runtime_checkable
12from lexigram.contracts.admin.page_content import PageContent
15@runtime_checkable
16class ManagementPageHandler(Protocol):
17 """Protocol for contributor management page handlers.
19 Implement this instead of registering dotted-string handler paths
20 in ``ManagementPageDefinition``. The framework discovers handlers
21 that satisfy this protocol and dispatches requests directly.
23 To support POST actions, define an additional ``handle_action(request, action_name)``
24 method. It is checked at runtime via ``hasattr``, not structurally typed here.
25 """
27 async def handle(self, request: Any) -> PageContent:
28 """Handle a GET request for the management page.
30 Returns:
31 Structured ``PageContent`` — the host renders it. Returning
32 raw HTML is a contract violation (the host replaces it with
33 an error page and logs).
34 """
35 ...
38# Backward-compatible alias — existing code importing AdminPageHandlerProtocol
39# continues to work without changes.
40AdminPageHandlerProtocol = ManagementPageHandler
42__all__ = ["AdminPageHandlerProtocol", "ManagementPageHandler"]