Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 3d4d9b1

Browse files
committed
Applying new structure
1 parent c8f98ff commit 3d4d9b1

File tree

5 files changed

+62
-35
lines changed

5 files changed

+62
-35
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ default_language_version:
44
python: python3.10
55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.3.0
7+
rev: v4.4.0
88
hooks:
99
- id: check-added-large-files
1010
- id: check-toml
1111
- id: check-yaml
1212
args:
1313
- --unsafe
1414
- id: end-of-file-fixer
15+
- id: debug-statements
1516
- id: trailing-whitespace
1617
- repo: https://github.com/asottile/pyupgrade
1718
rev: v2.37.3
@@ -21,29 +22,15 @@ repos:
2122
- --py3-plus
2223
- --keep-runtime-typing
2324
- repo: https://github.com/charliermarsh/ruff-pre-commit
24-
rev: v0.0.254
25+
rev: v0.3.0
2526
hooks:
2627
- id: ruff
2728
args: ["--fix", "--line-length=99"]
2829
- repo: https://github.com/psf/black
29-
rev: 22.8.0
30+
rev: 24.3.0
3031
hooks:
3132
- id: black
3233
args: ["--line-length=99"]
33-
- repo: https://github.com/pycqa/isort
34-
rev: 5.12.0
35-
hooks:
36-
- id: isort
37-
name: isort (python)
38-
args: ["--project=esmerald_admin", "--line-length=99"]
39-
- id: isort
40-
name: isort (cython)
41-
types: [cython]
42-
args: ["--project=esmerald_admin", "--line-length=99"]
43-
- id: isort
44-
name: isort (pyi)
45-
types: [pyi]
46-
args: ["--project=esmerald_admin", "--line-length=99"]
4734
ci:
4835
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
4936
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate

esmerald_admin/application.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from typing import Optional, Sequence
1+
from typing import Awaitable, Optional, Sequence, Union
22

33
from esmerald import Esmerald, HTTPException, Request, status
44
from esmerald.exceptions import ImproperlyConfigured
55
from lilya.middleware import Middleware
6+
from lilya.responses import Response
7+
from lilya.routing import Include, Path
8+
from lilya.staticfiles import StaticFiles
69
from sqladmin import Admin as SQLAdmin # noqa
710
from sqladmin import ModelView as SQLAModelView # noqa
811
from sqladmin._types import ENGINE_TYPE
@@ -61,12 +64,58 @@ def __init__(
6164
base_url=base_url,
6265
title=title,
6366
logo_url=logo_url,
64-
middlewares=middlewares, # type: ignore
65-
debug=debug,
6667
templates_dir=templates_dir,
68+
middlewares=middlewares, # type: ignore
6769
authentication_backend=authentication_backend,
6870
)
6971

72+
statics = StaticFiles(packages=["sqladmin"])
73+
74+
async def http_exception(
75+
request: Request, exc: Exception
76+
) -> Union[Response, Awaitable[Response]]:
77+
assert isinstance(exc, HTTPException)
78+
context = {
79+
"status_code": exc.status_code,
80+
"message": exc.detail,
81+
}
82+
return await self.templates.TemplateResponse( # type: ignore
83+
request, "error.html", context, status_code=exc.status_code # type: ignore
84+
)
85+
86+
routes = [
87+
Include("/statics", app=statics, name="statics"),
88+
Path("/", handler=self.index, name="index"),
89+
Path("/{identity}/list", handler=self.list, name="list"),
90+
Path("/{identity}/details/{pk:path}", handler=self.details, name="details"),
91+
Path(
92+
"/{identity}/delete",
93+
handler=self.delete,
94+
name="delete",
95+
methods=["DELETE"],
96+
),
97+
Path(
98+
"/{identity}/create",
99+
handler=self.create,
100+
name="create",
101+
methods=["GET", "POST"],
102+
),
103+
Path(
104+
"/{identity}/edit/{pk:path}",
105+
handler=self.edit,
106+
name="edit",
107+
methods=["GET", "POST"],
108+
),
109+
Path("/{identity}/export/{export_type}", handler=self.export, name="export"),
110+
Path("/{identity}/ajax/lookup", handler=self.ajax_lookup, name="ajax_lookup"),
111+
Path("/login", handler=self.login, name="login", methods=["GET", "POST"]),
112+
Path("/logout", handler=self.logout, name="logout", methods=["GET"]),
113+
]
114+
115+
self.admin.router.routes = routes # type: ignore
116+
self.admin.exception_handlers = {HTTPException: http_exception}
117+
self.admin.debug = debug
118+
self.app.include(base_url, app=self.admin, name="admin")
70119
self.app.router.activate() # type: ignore
71120

72121
def _find_model_view(self, identity: str) -> ModelView:

pyproject.toml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,10 @@ disallow_untyped_defs = true
103103
ignore_missing_imports = true
104104
no_implicit_optional = true
105105

106-
[tool.ruff]
107-
select = [
108-
"E", # pycodestyle errors
109-
"W", # pycodestyle warnings
110-
"F", # pyflakes
111-
"C", # flake8-comprehensions
112-
"B", # flake8-bugbear
113-
]
114-
ignore = [
115-
"E501", # line too long, handled by black
116-
"B008", # do not perform function calls in argument defaults
117-
"C901", # too complex
118-
]
106+
[tool.ruff.lint]
107+
select = ["E", "W", "F", "C", "B", "I"]
108+
ignore = ["E501", "B008", "C901", "B026"]
109+
119110

120111
[[tool.mypy.overrides]]
121112
module = "esmerald_admin.tests.*"

scripts/check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export MAIN="esmerald_admin"
1212

1313
set -x
1414

15-
${PREFIX}mypy $MAIN
15+
${PREFIX}mypy check $MAIN
1616
${PREFIX}ruff $SOURCE_FILES --line-length 99
1717
${PREFIX}black $SOURCE_FILES --check --diff --check --line-length 99
1818
${PREFIX}isort $SOURCE_FILES --check --diff --project=esmerald_admin --line-length 99

scripts/lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fi
1010
export SOURCE_FILES="esmerald_admin tests"
1111
set -x
1212

13-
${PREFIX}ruff $SOURCE_FILES --fix --line-length 99
13+
${PREFIX}ruff check $SOURCE_FILES --fix --line-length 99
1414
${PREFIX}black $SOURCE_FILES --line-length 99
1515
${PREFIX}isort $SOURCE_FILES --project=esmerald_admin --line-length 99
1616
${PREFIX}mypy esmerald_admin

0 commit comments

Comments
 (0)