Coverage for fastblocks/adapters/admin/sqladmin.py: 0%
33 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-09 00:47 -0700
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-09 00:47 -0700
1"""SQLAdmin Adapter for FastBlocks.
3Provides administrative interface using SQLAdmin for database model management.
4Includes automatic model discovery and registration with template integration.
6Author: lesleslie <les@wedgwoodwebworks.com>
7Created: 2025-01-12
8"""
10import typing as t
11from contextlib import suppress
12from uuid import UUID
14from acb.adapters import AdapterStatus
15from acb.depends import depends
16from starlette.applications import Starlette
17from fastblocks.applications import FastBlocks
19from ._base import AdminBase, AdminBaseSettings
21Auth = None
22Storage = None
23Models = None
24Sql = None
25Templates = None
28class AdminSettings(AdminBaseSettings): ...
31class Admin(AdminBase):
32 def __init__(
33 self,
34 app: Starlette = FastBlocks(),
35 templates: t.Any = depends(),
36 **kwargs: t.Any,
37 ) -> None:
38 super().__init__()
39 from sqladmin import Admin as SqlAdminBase
41 self._sqladmin = SqlAdminBase(app=app, **kwargs)
42 self.templates = templates.admin
44 def __getattr__(self, name: str) -> t.Any:
45 return getattr(self._sqladmin, name)
47 async def init(self) -> None:
48 with suppress(Exception):
49 models = depends.get("models")
50 if hasattr(models, "get_admin_models"):
51 admin_models = models.get_admin_models()
52 for model in admin_models:
53 self._sqladmin.add_view(model)
56MODULE_ID = UUID("01937d86-7f5d-7e6f-b120-4567890123de")
57MODULE_STATUS = AdapterStatus.STABLE
59with suppress(Exception):
60 depends.set(Admin)