From d690a61324d1d4deb76a8cdb5d0a8118c209ec76 Mon Sep 17 00:00:00 2001 From: pbrochar Date: Sun, 3 Mar 2024 18:58:18 +0100 Subject: [PATCH] add new template --- blitz/api/blitz_admin.py | 24 ++++++++++++++++++------ blitz/api/templates/index.html | 10 ++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/blitz/api/blitz_admin.py b/blitz/api/blitz_admin.py index 580cd42..c175bc0 100644 --- a/blitz/api/blitz_admin.py +++ b/blitz/api/blitz_admin.py @@ -1,8 +1,9 @@ +from functools import lru_cache from fastapi import FastAPI from starlette_admin import CustomView from blitz.db.db import get_sqlite_engine from starlette_admin.contrib.sqla import Admin, ModelView -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any, List from starlette_admin.views import Link from starlette.responses import Response from starlette.requests import Request @@ -14,21 +15,30 @@ class HomeView(CustomView): - async def render(self, request: Request, templates: Jinja2Templates) -> Response: - return templates.TemplateResponse("index.html", {"request": request}) + def __init__(self, blitz_app: "BlitzApp", *args: Any, **kwargs: Any): + self.blitz_app = blitz_app + super().__init__(*args, **kwargs) + + async def render( + self, + request: Request, + templates: Jinja2Templates, + ) -> Response: + return templates.TemplateResponse("index.html", {"request": request, "blitz_app": self.blitz_app}) class BlitzAdmin: def __init__(self, blitz_app: "BlitzApp", settings: Settings = get_settings()) -> None: self.blitz_app = blitz_app self.admin = Admin( - title=f"{blitz_app.name} Admin", + title=f"Blitz Admin - {blitz_app.name}", # FIXME find a better way to get the engine engine=get_sqlite_engine(blitz_app, in_memory=blitz_app._in_memory, file_name="app.db"), base_url="/admin/", templates_dir="blitz/api/templates", - index_view=HomeView("Home"), - logo_url="" + index_view=HomeView(blitz_app, "Home"), + statics_dir="blitz/ui/assets/", + logo_url="/admin/statics/blitz_logo_and_text_2.png", ) for resource in blitz_app.resources: self.admin.add_view(ModelView(resource.model)) @@ -40,6 +50,8 @@ def __init__(self, blitz_app: "BlitzApp", settings: Settings = get_settings()) - url=f"http://localhost:{settings.BLITZ_PORT}/dashboard/projects/{self.blitz_app.name}", ) ) + self.admin.add_view(Link(label="GitHub", icon="fa-brands fa-github", url="https://github.com/Paperz-org/blitz")) + self.admin.add_view(Link(label="Documentation", icon="fa fa-book", url="https://paperz-org.github.io/blitz/")) def mount_to(self, app: FastAPI) -> None: self.admin.mount_to(app) diff --git a/blitz/api/templates/index.html b/blitz/api/templates/index.html index d3bd4b2..05a5088 100644 --- a/blitz/api/templates/index.html +++ b/blitz/api/templates/index.html @@ -3,9 +3,8 @@
-

- Toto -

+

Welcome in your Blitz Admin panel

+
{% endblock %} {% block content %} -
Toto
+

+ {{ blitz_app.name}} Admin - v{{ blitz_app.file.config.version}} +

+
{{ blitz_app.file.config.description }}
{% endblock %} \ No newline at end of file