Skip to content

Commit

Permalink
add new template
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrochar committed Mar 3, 2024
1 parent 6b719bf commit d690a61
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
24 changes: 18 additions & 6 deletions blitz/api/blitz_admin.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand All @@ -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)
10 changes: 6 additions & 4 deletions blitz/api/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<div class="d-flex justify-content-between align-items-center">
<div class="row g-2 align-items-center">
<div class="col">
<h2 class="page-title">
Toto
</h2>
<h1>Welcome in your Blitz Admin panel</h1>

</div>
</div>
<ol class="breadcrumb">
Expand All @@ -17,5 +16,8 @@ <h2 class="page-title">
</div>
{% endblock %}
{% block content %}
<div>Toto</div>
<h2 class="page-title">
{{ blitz_app.name}} Admin - v{{ blitz_app.file.config.version}}
</h2>
<div>{{ blitz_app.file.config.description }}</div>
{% endblock %}

0 comments on commit d690a61

Please sign in to comment.