FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge branch 'fastapi-admin:dev' into locale/tr · Medical-FastAPI/fastapi-admin@16785eb · GitHub

Repository navigation

Commit 16785eb

Browse files
Merge branch 'fastapi-admin:dev' into locale/tr
2 parents af6b327 + 66b69c2 commit 16785eb

4 files changed

Lines changed: 793 additions & 713 deletions

File tree

‎examples/main.py‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from contextlib import asynccontextmanager
23

34
import redis.asyncio as redis
45
import uvicorn
@@ -27,8 +28,30 @@
2728
)
2829

2930

31+
@asynccontextmanager
32+
async def lifespan(app: FastAPI):
33+
r = redis.from_url(
34+
settings.REDIS_URL,
35+
decode_responses=True,
36+
encoding="utf8",
37+
)
38+
await admin_app.configure(
39+
logo_url="https://preview.tabler.io/static/logo-white.svg",
40+
template_folders=[os.path.join(BASE_DIR, "templates")],
41+
favicon_url="https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png",
42+
providers=[
43+
LoginProvider(
44+
login_logo_url="https://preview.tabler.io/static/logo.svg",
45+
admin_model=Admin,
46+
)
47+
],
48+
redis=r,
49+
)
50+
yield
51+
52+
3053
def create_app():
31-
app = FastAPI()
54+
app = FastAPI(lifespan=lifespan)
3255
app.mount(
3356
"/static",
3457
StaticFiles(directory=os.path.join(BASE_DIR, "static")),
@@ -44,26 +67,6 @@ async def index():
4467
admin_app.add_exception_handler(HTTP_403_FORBIDDEN, forbidden_error_exception)
4568
admin_app.add_exception_handler(HTTP_401_UNAUTHORIZED, unauthorized_error_exception)
4669

47-
@app.on_event("startup")
48-
async def startup():
49-
r = redis.from_url(
50-
settings.REDIS_URL,
51-
decode_responses=True,
52-
encoding="utf8",
53-
)
54-
await admin_app.configure(
55-
logo_url="https://preview.tabler.io/static/logo-white.svg",
56-
template_folders=[os.path.join(BASE_DIR, "templates")],
57-
favicon_url="https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png",
58-
providers=[
59-
LoginProvider(
60-
login_logo_url="https://preview.tabler.io/static/logo.svg",
61-
admin_model=Admin,
62-
)
63-
],
64-
redis=r,
65-
)
66-
6770
app.mount("/admin", admin_app)
6871
app.add_middleware(
6972
CORSMiddleware,

‎fastapi_admin/providers/login.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def authenticate(
119119
request: Request,
120120
call_next: RequestResponseEndpoint,
121121
):
122-
redis = request.app.redis # type:Redis
122+
redis = request.app.redis # type:ignore
123123
token = request.cookies.get(self.access_token)
124124
path = request.scope["path"]
125125
admin = None

‎fastapi_admin/widgets/inputs.py‎

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Input(Widget):
1515
template = "widgets/inputs/input.html"
1616

1717
def __init__(
18-
self, help_text: Optional[str] = None, default: Any = None, null: bool = False, **context
18+
self, help_text: Optional[str] = None, default: Any = None, null: bool = False, **context
1919
):
2020
super().__init__(null=null, help_text=help_text, **context)
2121
self.default = default
@@ -44,12 +44,12 @@ class Text(Input):
4444
input_type: Optional[str] = "text"
4545

4646
def __init__(
47-
self,
48-
help_text: Optional[str] = None,
49-
default: Any = None,
50-
null: bool = False,
51-
placeholder: str = "",
52-
disabled: bool = False,
47+
self,
48+
help_text: Optional[str] = None,
49+
default: Any = None,
50+
null: bool = False,
51+
placeholder: str = "",
52+
disabled: bool = False,
5353
):
5454
super().__init__(
5555
null=null,
@@ -65,11 +65,11 @@ class Select(Input):
6565
template = "widgets/inputs/select.html"
6666

6767
def __init__(
68-
self,
69-
help_text: Optional[str] = None,
70-
default: Any = None,
71-
null: bool = False,
72-
disabled: bool = False,
68+
self,
69+
help_text: Optional[str] = None,
70+
default: Any = None,
71+
null: bool = False,
72+
disabled: bool = False,
7373
):
7474
super().__init__(help_text=help_text, null=null, default=default, disabled=disabled)
7575

@@ -91,12 +91,12 @@ async def render(self, request: Request, value: Any):
9191

9292
class ForeignKey(Select):
9393
def __init__(
94-
self,
95-
model: Type[Model],
96-
default: Any = None,
97-
null: bool = False,
98-
disabled: bool = False,
99-
help_text: Optional[str] = None,
94+
self,
95+
model: Type[Model],
96+
default: Any = None,
97+
null: bool = False,
98+
disabled: bool = False,
99+
help_text: Optional[str] = None,
100100
):
101101
super().__init__(help_text=help_text, default=default, null=null, disabled=disabled)
102102
self.model = model
@@ -116,10 +116,10 @@ class ManyToMany(Select):
116116
template = "widgets/inputs/many_to_many.html"
117117

118118
def __init__(
119-
self,
120-
model: Type[Model],
121-
disabled: bool = False,
122-
help_text: Optional[str] = None,
119+
self,
120+
model: Type[Model],
121+
disabled: bool = False,
122+
help_text: Optional[str] = None,
123123
):
124124
super().__init__(help_text=help_text, disabled=disabled)
125125
self.model = model
@@ -144,13 +144,13 @@ async def render(self, request: Request, value: Any):
144144

145145
class Enum(Select):
146146
def __init__(
147-
self,
148-
enum: Type[EnumCLS],
149-
default: Any = None,
150-
enum_type: Type = int,
151-
null: bool = False,
152-
disabled: bool = False,
153-
help_text: Optional[str] = None,
147+
self,
148+
enum: Type[EnumCLS],
149+
default: Any = None,
150+
enum_type: Type = int,
151+
null: bool = False,
152+
disabled: bool = False,
153+
help_text: Optional[str] = None,
154154
):
155155
super().__init__(help_text=help_text, default=default, null=null, disabled=disabled)
156156
self.enum = enum
@@ -174,10 +174,10 @@ class Json(Input):
174174
template = "widgets/inputs/json.html"
175175

176176
def __init__(
177-
self,
178-
help_text: Optional[str] = None,
179-
null: bool = False,
180-
options: Optional[dict] = None,
177+
self,
178+
help_text: Optional[str] = None,
179+
null: bool = False,
180+
options: Optional[dict] = None,
181181
):
182182
"""
183183
options config to jsoneditor, see https://github.com/josdejong/jsoneditor
@@ -215,12 +215,12 @@ class File(Input):
215215
input_type = "file"
216216

217217
def __init__(
218-
self,
219-
upload: FileUpload,
220-
default: Any = None,
221-
null: bool = False,
222-
disabled: bool = False,
223-
help_text: Optional[str] = None,
218+
self,
219+
upload: FileUpload,
220+
default: Any = None,
221+
null: bool = False,
222+
disabled: bool = False,
223+
help_text: Optional[str] = None,
224224
):
225225
super().__init__(
226226
null=null,
@@ -246,11 +246,11 @@ class Radio(Select):
246246
template = "widgets/inputs/radio.html"
247247

248248
def __init__(
249-
self,
250-
options: List[Tuple[str, Any]],
251-
help_text: Optional[str] = None,
252-
default: Any = None,
253-
disabled: bool = False,
249+
self,
250+
options: List[Tuple[str, Any]],
251+
help_text: Optional[str] = None,
252+
default: Any = None,
253+
disabled: bool = False,
254254
):
255255
super().__init__(default=default, disabled=disabled, help_text=help_text)
256256
self.options = options

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL