Skip to content

Commit f0989f1

Browse files
committed
Optimisation on unit tests. Fix for pony orm.
1 parent aa96902 commit f0989f1

26 files changed

Lines changed: 648 additions & 335 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ dmypy.json
135135

136136
*.code-workspace
137137
.idea/
138+
139+
:sharedmemory:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ lint:
3131
@echo "Run frontend linters"
3232
@exec make -C frontend lint
3333

34+
# -n auto : fix django
3435
.PHONY: test
3536
test:
36-
@exec poetry run python generate_db.py
37-
@exec env ADMIN_ENV_FILE=example.env poetry run pytest --cov=fastadmin --cov-report=term-missing --cov-report=xml --cov-fail-under=80 -s tests
37+
@exec poetry run pytest --cov=fastadmin --cov-report=term-missing --cov-report=xml --cov-fail-under=80 -s tests
3838
@exec make -C frontend test
3939

4040
.PHONY: kill

docs/build.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def read_cls_docstring(cls):
3939

4040
def get_versions():
4141
return [
42+
{
43+
"version": "0.2.11",
44+
"changes": [
45+
"Optimisation on unit tests. Fix for pony orm. Optimisation on search for tortoise orm.",
46+
],
47+
},
4248
{
4349
"version": "0.2.10",
4450
"changes": [

docs/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

example.env

Lines changed: 0 additions & 3 deletions
This file was deleted.

fastadmin/api/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def convert_id(id: str | int | UUID) -> int | UUID | None:
5353
if re.fullmatch(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", id):
5454
return UUID(id)
5555

56-
logger.error("Invalid id: %s", id)
56+
logger.warning("Invalid id: %s", id)
5757
return None
5858

5959

@@ -101,6 +101,7 @@ async def sign_in(
101101
) -> str:
102102
model = settings.ADMIN_USER_MODEL
103103
admin_model = get_admin_model(model)
104+
104105
if not admin_model:
105106
raise AdminApiException(401, detail=f"{model} model is not registered.")
106107

fastadmin/models/orms/ponyorm.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from uuid import UUID
44

55
from asgiref.sync import sync_to_async
6-
from pony.orm import commit, db_session, desc, flush, select
6+
from pony.orm import commit, db_session, desc, flush
77

88
from fastadmin.models.base import InlineModelAdmin, ModelAdmin
99
from fastadmin.models.schemas import ModelFieldWidgetSchema, WidgetType
@@ -233,7 +233,7 @@ def orm_get_list(
233233
:return: A tuple of list of objects and total count.
234234
"""
235235

236-
qs = select(m for m in self.model_cls)
236+
qs = getattr(self.model_cls, "select")(lambda m: m) # noqa: B009
237237
if filters:
238238
for field_with_condition, value in filters.items():
239239
field = field_with_condition[0]
@@ -256,14 +256,17 @@ def orm_get_list(
256256
case "contains":
257257
pony_condition = "in"
258258
case "icontains":
259+
# TODO: support icontains here
259260
pony_condition = "in"
260261
filter_expr = f""""{value}" {pony_condition} m.{field}"""
261262
qs = qs.filter(filter_expr)
262263

263264
if search and self.search_fields:
264265
ids = []
265-
for f in self.search_fields:
266-
qs_ids = qs.filter(lambda m: search.lower() in getattr(m, f).lower()) # noqa: B023
266+
for search_field in self.search_fields:
267+
# TODO: support icontains here
268+
filter_expr = f""""{search}" in m.{search_field}"""
269+
qs_ids = qs.filter(filter_expr)
267270
ids += [o.id for o in qs_ids]
268271
qs = qs.filter(lambda m: m.id in set(ids))
269272

fastadmin/static/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate_db.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

poetry.lock

Lines changed: 35 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)