fastadmin 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastadmin/api/frameworks/django/app/views.py +9 -17
- fastadmin/api/frameworks/fastapi/views.py +9 -5
- fastadmin/api/frameworks/flask/app.py +0 -1
- fastadmin/api/frameworks/flask/views.py +9 -3
- fastadmin/api/helpers.py +9 -0
- fastadmin/static/index.min.js +1 -1
- fastadmin/templates/index.html +3 -3
- {fastadmin-0.2.2.dist-info → fastadmin-0.2.3.dist-info}/METADATA +3 -6
- {fastadmin-0.2.2.dist-info → fastadmin-0.2.3.dist-info}/RECORD +11 -11
- {fastadmin-0.2.2.dist-info → fastadmin-0.2.3.dist-info}/LICENSE +0 -0
- {fastadmin-0.2.2.dist-info → fastadmin-0.2.3.dist-info}/WHEEL +0 -0
@@ -1,27 +1,19 @@
|
|
1
|
-
import typing
|
2
|
-
|
3
|
-
import jinja2
|
4
1
|
from django.http import HttpResponse
|
5
2
|
|
3
|
+
from fastadmin.api.helpers import get_template
|
6
4
|
from fastadmin.settings import ROOT_DIR, settings
|
7
5
|
|
8
6
|
|
9
|
-
def
|
10
|
-
loader = jinja2.FileSystemLoader(directory)
|
11
|
-
env_options.setdefault("loader", loader)
|
12
|
-
env_options.setdefault("autoescape", True)
|
13
|
-
|
14
|
-
return jinja2.Environment(**env_options) # noqa: S701
|
15
|
-
|
16
|
-
|
17
|
-
async def index(request):
|
7
|
+
def index(request):
|
18
8
|
"""This method is used to render index page.
|
19
9
|
|
20
10
|
:params request: a request object.
|
21
11
|
:return: A response object.
|
22
12
|
"""
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
template = get_template(
|
14
|
+
ROOT_DIR / "templates" / "index.html",
|
15
|
+
{
|
16
|
+
"ADMIN_PREFIX": settings.ADMIN_PREFIX,
|
17
|
+
},
|
18
|
+
)
|
19
|
+
return HttpResponse(template)
|
@@ -1,21 +1,25 @@
|
|
1
1
|
import logging
|
2
2
|
|
3
|
-
from fastapi import APIRouter
|
3
|
+
from fastapi import APIRouter
|
4
4
|
from fastapi.responses import HTMLResponse
|
5
|
-
from fastapi.templating import Jinja2Templates
|
6
5
|
|
6
|
+
from fastadmin.api.helpers import get_template
|
7
7
|
from fastadmin.settings import ROOT_DIR, settings
|
8
8
|
|
9
9
|
logger = logging.getLogger(__name__)
|
10
10
|
router = APIRouter()
|
11
|
-
templates = Jinja2Templates(directory=ROOT_DIR / "templates")
|
12
11
|
|
13
12
|
|
14
13
|
@router.get("/", response_class=HTMLResponse)
|
15
|
-
|
14
|
+
def index():
|
16
15
|
"""This method is used to render index page.
|
17
16
|
|
18
17
|
:params request: a request object.
|
19
18
|
:return: A response object.
|
20
19
|
"""
|
21
|
-
return
|
20
|
+
return get_template(
|
21
|
+
ROOT_DIR / "templates" / "index.html",
|
22
|
+
{
|
23
|
+
"ADMIN_PREFIX": settings.ADMIN_PREFIX,
|
24
|
+
},
|
25
|
+
)
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import logging
|
2
2
|
|
3
|
-
from flask import Blueprint
|
3
|
+
from flask import Blueprint
|
4
4
|
|
5
|
-
from fastadmin.
|
5
|
+
from fastadmin.api.helpers import get_template
|
6
|
+
from fastadmin.settings import ROOT_DIR, settings
|
6
7
|
|
7
8
|
logger = logging.getLogger(__name__)
|
8
9
|
views_router = Blueprint(
|
@@ -17,4 +18,9 @@ def index():
|
|
17
18
|
|
18
19
|
:return: A response object.
|
19
20
|
"""
|
20
|
-
return
|
21
|
+
return get_template(
|
22
|
+
ROOT_DIR / "templates" / "index.html",
|
23
|
+
{
|
24
|
+
"ADMIN_PREFIX": settings.ADMIN_PREFIX,
|
25
|
+
},
|
26
|
+
)
|
fastadmin/api/helpers.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import base64
|
2
2
|
import binascii
|
3
|
+
from pathlib import Path
|
3
4
|
from uuid import UUID
|
4
5
|
|
5
6
|
from fastadmin.models.schemas import ModelFieldWidgetSchema
|
@@ -78,3 +79,11 @@ def is_valid_base64(value: str) -> bool:
|
|
78
79
|
return True
|
79
80
|
except binascii.Error:
|
80
81
|
return False
|
82
|
+
|
83
|
+
|
84
|
+
def get_template(template: Path, context: dict) -> str:
|
85
|
+
with Path.open(template, "r") as file:
|
86
|
+
content = file.read()
|
87
|
+
for key, value in context.items():
|
88
|
+
content = content.replace(f"{{{{{key}}}}}", value)
|
89
|
+
return content
|