Coverage for src/lexigram/admin/pages/base.py: 0%
15 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 23:18 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 23:18 +0800
1"""Page ABC: base class for admin pages.
3.. experimental::
4"""
6from __future__ import annotations
8from abc import ABC, abstractmethod
9from typing import Any
11from lexigram.admin.pages.types import NavigationEntry, PageResponse
14class MethodNotAllowedError(RuntimeError):
15 """Raised when a page does not support the POST method."""
18class Page(ABC):
19 """Base class for admin pages.
21 A Page is the unit of routing. Each page declares its title,
22 path, and optional navigation entry. Subclasses implement
23 ``view()`` and optionally ``post()``.
24 """
26 title: str
27 path: str = ""
29 @abstractmethod
30 async def view(self, request: Any) -> PageResponse:
31 """Render the page on GET request."""
32 ...
34 async def post(self, request: Any) -> PageResponse:
35 """Handle POST request. Default raises MethodNotAllowedError."""
36 raise MethodNotAllowedError("POST not supported on this page")
38 def navigation(self) -> NavigationEntry | None:
39 """Return a navigation entry or None to skip the sidebar."""
40 return None
43__all__ = [
44 "Page",
45]