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

1"""Page ABC: base class for admin pages. 

2 

3.. experimental:: 

4""" 

5 

6from __future__ import annotations 

7 

8from abc import ABC, abstractmethod 

9from typing import Any 

10 

11from lexigram.admin.pages.types import NavigationEntry, PageResponse 

12 

13 

14class MethodNotAllowedError(RuntimeError): 

15 """Raised when a page does not support the POST method.""" 

16 

17 

18class Page(ABC): 

19 """Base class for admin pages. 

20 

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 """ 

25 

26 title: str 

27 path: str = "" 

28 

29 @abstractmethod 

30 async def view(self, request: Any) -> PageResponse: 

31 """Render the page on GET request.""" 

32 ... 

33 

34 async def post(self, request: Any) -> PageResponse: 

35 """Handle POST request. Default raises MethodNotAllowedError.""" 

36 raise MethodNotAllowedError("POST not supported on this page") 

37 

38 def navigation(self) -> NavigationEntry | None: 

39 """Return a navigation entry or None to skip the sidebar.""" 

40 return None 

41 

42 

43__all__ = [ 

44 "Page", 

45]