fastadmin 0.2.1__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/api.py +2 -2
- fastadmin/api/frameworks/django/app/views.py +9 -17
- fastadmin/api/frameworks/fastapi/views.py +9 -5
- fastadmin/api/frameworks/flask/app.py +2 -3
- fastadmin/api/frameworks/flask/views.py +9 -3
- fastadmin/api/helpers.py +9 -0
- fastadmin/models/base.py +17 -1
- fastadmin/models/helpers.py +1 -1
- fastadmin/models/orms/ponyorm.py +0 -1
- fastadmin/static/index.html +2 -2
- fastadmin/static/index.min.js +71 -71
- fastadmin/templates/index.html +3 -3
- {fastadmin-0.2.1.dist-info → fastadmin-0.2.3.dist-info}/METADATA +5 -7
- {fastadmin-0.2.1.dist-info → fastadmin-0.2.3.dist-info}/RECORD +16 -16
- {fastadmin-0.2.1.dist-info → fastadmin-0.2.3.dist-info}/LICENSE +0 -0
- {fastadmin-0.2.1.dist-info → fastadmin-0.2.3.dist-info}/WHEEL +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
import json
|
2
2
|
import logging
|
3
3
|
from dataclasses import asdict
|
4
|
-
from datetime import datetime
|
4
|
+
from datetime import datetime, time
|
5
5
|
from functools import wraps
|
6
6
|
from uuid import UUID
|
7
7
|
|
@@ -23,7 +23,7 @@ api_service = ApiService()
|
|
23
23
|
|
24
24
|
class JsonEncoder(DjangoJSONEncoder):
|
25
25
|
def default(self, o):
|
26
|
-
if isinstance(o, datetime):
|
26
|
+
if isinstance(o, datetime | time):
|
27
27
|
return o.isoformat()
|
28
28
|
if isinstance(o, UUID):
|
29
29
|
return str(o)
|
@@ -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,5 +1,5 @@
|
|
1
1
|
import logging
|
2
|
-
from datetime import date
|
2
|
+
from datetime import date, time
|
3
3
|
|
4
4
|
from flask import Blueprint
|
5
5
|
from flask.json.provider import DefaultJSONProvider
|
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
|
|
14
14
|
|
15
15
|
class JSONProvider(DefaultJSONProvider):
|
16
16
|
def default(self, o):
|
17
|
-
if isinstance(o, date):
|
17
|
+
if isinstance(o, date | time):
|
18
18
|
return o.isoformat()
|
19
19
|
return super().default(o)
|
20
20
|
|
@@ -25,7 +25,6 @@ app = Blueprint(
|
|
25
25
|
url_prefix="/parent",
|
26
26
|
static_url_path="/static",
|
27
27
|
static_folder=ROOT_DIR / "static",
|
28
|
-
template_folder=ROOT_DIR / "templates",
|
29
28
|
)
|
30
29
|
app.register_blueprint(views_router)
|
31
30
|
app.register_blueprint(api_router)
|
@@ -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
|
fastadmin/models/base.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import csv
|
2
|
+
import datetime
|
2
3
|
import inspect
|
3
4
|
import json
|
4
5
|
from collections.abc import Sequence
|
@@ -383,6 +384,17 @@ class BaseModelAdmin:
|
|
383
384
|
|
384
385
|
return obj_dict
|
385
386
|
|
387
|
+
def deserialize_value(self, field: ModelFieldWidgetSchema, value: Any) -> Any:
|
388
|
+
if not value:
|
389
|
+
return value
|
390
|
+
match field.form_widget_type:
|
391
|
+
case WidgetType.TimePicker:
|
392
|
+
return datetime.datetime.fromisoformat(value).time()
|
393
|
+
case WidgetType.DatePicker | WidgetType.DateTimePicker:
|
394
|
+
return datetime.datetime.fromisoformat(value)
|
395
|
+
case _:
|
396
|
+
return value
|
397
|
+
|
386
398
|
async def get_list(
|
387
399
|
self,
|
388
400
|
offset: int | None = None,
|
@@ -434,7 +446,11 @@ class BaseModelAdmin:
|
|
434
446
|
m2m_fields = self.get_model_fields_with_widget_types(with_m2m=True)
|
435
447
|
upload_fields = self.get_model_fields_with_widget_types(with_upload=True)
|
436
448
|
|
437
|
-
fields_payload = {
|
449
|
+
fields_payload = {
|
450
|
+
field.column_name: self.deserialize_value(field, payload[field.name])
|
451
|
+
for field in fields
|
452
|
+
if field.name in payload
|
453
|
+
}
|
438
454
|
obj = await self.orm_save_obj(id, fields_payload)
|
439
455
|
if not obj:
|
440
456
|
return None
|
fastadmin/models/helpers.py
CHANGED
@@ -62,7 +62,7 @@ def get_admin_model(orm_model_cls: str | Any) -> ModelAdmin | None:
|
|
62
62
|
model_name_prefix = admin_model.model_name_prefix
|
63
63
|
if model_name_prefix:
|
64
64
|
model_name = f"{model_name_prefix}.{model_name}"
|
65
|
-
if orm_model_cls
|
65
|
+
if orm_model_cls == model_name:
|
66
66
|
return admin_model
|
67
67
|
return None
|
68
68
|
|
fastadmin/models/orms/ponyorm.py
CHANGED
fastadmin/static/index.html
CHANGED
@@ -7,8 +7,8 @@
|
|
7
7
|
<meta name="description" content="Fast Admin"/>
|
8
8
|
<title>Fast Admin</title>
|
9
9
|
<script>
|
10
|
-
window.SERVER_DOMAIN = 'http://localhost:
|
11
|
-
window.SERVER_URL = 'http://localhost:
|
10
|
+
window.SERVER_DOMAIN = 'http://localhost:8000';
|
11
|
+
window.SERVER_URL = 'http://localhost:8000/admin/api';
|
12
12
|
</script>
|
13
13
|
<script type="module" crossorigin src="/index.min.js"></script>
|
14
14
|
<link rel="stylesheet" crossorigin href="/index.min.css">
|