Skip to content

Commit

Permalink
Removed pydantic anmd isort from dependencies. Fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
vsdudakov committed Aug 2, 2024
1 parent 8807b56 commit 6ffa95e
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 260 deletions.
19 changes: 10 additions & 9 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
</pre> <p class="alert alert-warning"> Note: Settings without default values are required. </p> </section> <hr class=small-divider> <section id=dashboard-widget-admins> <h2>Dashboard Widget Admins</h2> <section id=registering-widgets> <h3>Registering Widgets</h3> <p class=lead> Register Dashboard widgets </p> <ul class="nav nav-tabs" id=register_dashboard_widgets role=tablist> <li class=nav-item role=presentation> <button class="nav-link active" id=dashboard_tortoise_orm data-bs-toggle=tab data-bs-target=#dashboard_tortoise_orm-pane type=button role=tab aria-controls=dashboard_tortoise_orm aria-selected=true>Tortoise ORM</button> </li> <li class=nav-item role=presentation> <button class="nav-link " id=dashboard_django_orm data-bs-toggle=tab data-bs-target=#dashboard_django_orm-pane type=button role=tab aria-controls=dashboard_django_orm aria-selected=false>Django ORM</button> </li> <li class=nav-item role=presentation> <button class="nav-link " id=dashboard_sql_alchemy data-bs-toggle=tab data-bs-target=#dashboard_sql_alchemy-pane type=button role=tab aria-controls=dashboard_sql_alchemy aria-selected=false>SQL Alchemy</button> </li> <li class=nav-item role=presentation> <button class="nav-link " id=dashboard_pony_orm data-bs-toggle=tab data-bs-target=#dashboard_pony_orm-pane type=button role=tab aria-controls=dashboard_pony_orm aria-selected=false>Pony ORM</button> </li> </ul> <div class=tab-content id=register_dashboard_widgets-content> <div class="tab-pane fade show active" id=dashboard_tortoise_orm-pane role=tabpanel aria-labelledby=dashboard_tortoise_orm tabindex=0> <pre>
<code class=language-python>
from datetime import datetime, timedelta, timezone
from typing import Any

from tortoise import Tortoise, fields
from tortoise.models import Model
Expand All @@ -311,8 +312,8 @@
x_field = "date"
y_field = "count"
x_field_filter_widget_type = WidgetType.DatePicker
x_field_filter_widget_props = {"picker": "month"}
x_field_periods = ["day", "week", "month", "year"]
x_field_filter_widget_props: dict[str, Any] = {"picker": "month"} # noqa: RUF012
x_field_periods = ["day", "week", "month", "year"] # noqa: RUF012

async def get_data(
self,
Expand All @@ -331,7 +332,7 @@
else:
max_x_field_date = datetime.fromisoformat(max_x_field.replace("Z", "+00:00"))

if not period_x_field or period_x_field not in self.x_field_periods:
if not period_x_field or period_x_field not in (self.x_field_periods or []):
period_x_field = "month"

results = await conn.execute_query_dict(
Expand Down Expand Up @@ -380,8 +381,8 @@
x_field = "date"
y_field = "count"
x_field_filter_widget_type = WidgetType.DatePicker
x_field_filter_widget_props = {"picker": "month"}
x_field_periods = ["day", "week", "month", "year"]
x_field_filter_widget_props = {"picker": "month"} # noqa: RUF012
x_field_periods = ["day", "week", "month", "year"] # noqa: RUF012

def get_data( # type: ignore [override]
self,
Expand Down Expand Up @@ -512,7 +513,7 @@
(None, {"fields": ("username", "hash_password")}),
("Permissions", {"fields": ("is_active", "is_superuser")}),
)
formfield_overrides = {
formfield_overrides = { # noqa: RUF012
"username": (WidgetType.SlugInput, {"required": True}),
"password": (WidgetType.PasswordInput, {"passwordModalForm": True}),
}
Expand Down Expand Up @@ -622,7 +623,7 @@
# formfield_overrides = {
# "description": (WidgetType.RichTextArea, {})
# }
formfield_overrides: dict[str, tuple[WidgetType, dict]] = {}
formfield_overrides: dict[str, tuple[WidgetType, dict]] = {} # noqa: RUF012

# Set list_display to control which fields are displayed on the list page of the admin.
# If you don't set list_display, the admin site will display a single column that displays the __str__() representation of each object
Expand All @@ -639,7 +640,7 @@
# list_display_widths = {
# "id": "100px",
# }
list_display_widths: dict[str, str] = {}
list_display_widths: dict[str, str] = {} # noqa: RUF012

# Set list_filter to activate filters in the tabel columns of the list page of the admin.
# Example of usage: list_filter = ("is_superuser", "is_active", "created_at")
Expand Down Expand Up @@ -1206,7 +1207,7 @@
(None, {"fields": ("username", "hash_password")}),
("Permissions", {"fields": ("is_active", "is_superuser")}),
)
formfield_overrides = {
formfield_overrides = { # noqa: RUF012
"username": (WidgetType.SlugInput, {"required": True}),
"password": (WidgetType.PasswordInput, {"passwordModalForm": True}),
}
Expand Down
4 changes: 2 additions & 2 deletions examples/dashboard/djangoorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class UsersDashboardWidgetAdmin(DashboardWidgetAdmin):
x_field = "date"
y_field = "count"
x_field_filter_widget_type = WidgetType.DatePicker
x_field_filter_widget_props = {"picker": "month"}
x_field_periods = ["day", "week", "month", "year"]
x_field_filter_widget_props = {"picker": "month"} # noqa: RUF012
x_field_periods = ["day", "week", "month", "year"] # noqa: RUF012

def get_data( # type: ignore [override]
self,
Expand Down
7 changes: 4 additions & 3 deletions examples/dashboard/tortoise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timedelta, timezone
from typing import Any

from tortoise import Tortoise, fields
from tortoise.models import Model
Expand All @@ -23,8 +24,8 @@ class UsersDashboardWidgetAdmin(DashboardWidgetAdmin):
x_field = "date"
y_field = "count"
x_field_filter_widget_type = WidgetType.DatePicker
x_field_filter_widget_props = {"picker": "month"}
x_field_periods = ["day", "week", "month", "year"]
x_field_filter_widget_props: dict[str, Any] = {"picker": "month"} # noqa: RUF012
x_field_periods = ["day", "week", "month", "year"] # noqa: RUF012

async def get_data(
self,
Expand All @@ -43,7 +44,7 @@ async def get_data(
else:
max_x_field_date = datetime.fromisoformat(max_x_field.replace("Z", "+00:00"))

if not period_x_field or period_x_field not in self.x_field_periods:
if not period_x_field or period_x_field not in (self.x_field_periods or []):
period_x_field = "month"

results = await conn.execute_query_dict(
Expand Down
2 changes: 1 addition & 1 deletion examples/inlines/tortoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class UserAdmin(TortoiseModelAdmin):
(None, {"fields": ("username", "hash_password")}),
("Permissions", {"fields": ("is_active", "is_superuser")}),
)
formfield_overrides = {
formfield_overrides = { # noqa: RUF012
"username": (WidgetType.SlugInput, {"required": True}),
"password": (WidgetType.PasswordInput, {"passwordModalForm": True}),
}
Expand Down
2 changes: 1 addition & 1 deletion examples/models/tortoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class UserAdmin(TortoiseModelAdmin):
(None, {"fields": ("username", "hash_password")}),
("Permissions", {"fields": ("is_active", "is_superuser")}),
)
formfield_overrides = {
formfield_overrides = { # noqa: RUF012
"username": (WidgetType.SlugInput, {"required": True}),
"password": (WidgetType.PasswordInput, {"passwordModalForm": True}),
}
Expand Down
4 changes: 2 additions & 2 deletions fastadmin/api/frameworks/fastapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async def list_objs(
request: Request,
model: str,
search: str | None = None,
sort_by: str = None,
sort_by: str | None = None,
offset: int | None = 0,
limit: int | None = 10,
):
Expand Down Expand Up @@ -238,7 +238,7 @@ async def export(
model: str,
payload: ExportInputSchema,
search: str | None = None,
sort_by: str = None,
sort_by: str | None = None,
):
"""This method is used to export a list of objects.
Expand Down
28 changes: 14 additions & 14 deletions fastadmin/api/frameworks/flask/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def sign_in() -> Response:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/sign-out", methods=["POST"])
Expand All @@ -57,7 +57,7 @@ async def sign_out() -> Response:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/me", methods=["GET"])
Expand All @@ -79,7 +79,7 @@ async def me() -> dict:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/dashboard-widget/<string:model>", methods=["GET"])
Expand Down Expand Up @@ -109,7 +109,7 @@ async def dashboard_widget(model: str) -> dict:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/list/<string:model>", methods=["GET"])
Expand Down Expand Up @@ -143,14 +143,14 @@ async def list_objs(model: str) -> dict:
"total": total,
"results": objs,
}
except ValueError:
except ValueError as e:
http_exception = HTTPException("Invalid format of get parameters")
http_exception.code = 422
raise http_exception
raise http_exception from e
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/retrieve/<string:model>/<string:id>", methods=["GET"])
Expand All @@ -174,7 +174,7 @@ async def get(model: str, id: UUID | int) -> dict:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/add/<string:model>", methods=["POST"])
Expand All @@ -195,7 +195,7 @@ async def add(model: str) -> dict:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/change-password/<string:id>", methods=["PATCH"]) # type: ignore [type-var]
Expand All @@ -221,7 +221,7 @@ async def change_password(id: UUID | int) -> UUID | int:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/change/<string:model>/<string:id>", methods=["PATCH"])
Expand All @@ -248,7 +248,7 @@ async def change(model: str, id: UUID | int) -> dict:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/export/<string:model>", methods=["POST"])
Expand Down Expand Up @@ -282,7 +282,7 @@ async def export(model: str) -> Response:
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/delete/<string:model>/<string:id>", methods=["DELETE"]) # type: ignore [type-var]
Expand All @@ -309,7 +309,7 @@ async def delete(
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/action/<string:model>/<string:action>", methods=["POST"])
Expand Down Expand Up @@ -337,7 +337,7 @@ async def action(
except AdminApiException as e:
http_exception = HTTPException(e.detail)
http_exception.code = e.status_code
raise http_exception
raise http_exception from e


@api_router.route("/configuration", methods=["GET"])
Expand Down
4 changes: 2 additions & 2 deletions fastadmin/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class BaseModelAdmin:
# formfield_overrides = {
# "description": (WidgetType.RichTextArea, {})
# }
formfield_overrides: dict[str, tuple[WidgetType, dict]] = {}
formfield_overrides: dict[str, tuple[WidgetType, dict]] = {} # noqa: RUF012

# Set list_display to control which fields are displayed on the list page of the admin.
# If you don't set list_display, the admin site will display a single column that displays the __str__() representation of each object
Expand All @@ -104,7 +104,7 @@ class BaseModelAdmin:
# list_display_widths = {
# "id": "100px",
# }
list_display_widths: dict[str, str] = {}
list_display_widths: dict[str, str] = {} # noqa: RUF012

# Set list_filter to activate filters in the tabel columns of the list page of the admin.
# Example of usage: list_filter = ("is_superuser", "is_active", "created_at")
Expand Down
2 changes: 1 addition & 1 deletion fastadmin/models/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def action(function=None, *, description: str = None):
def action(function=None, *, description: str | None = None):
"""Conveniently add attributes to an action function:
Example of usage:
Expand Down
Loading

0 comments on commit 6ffa95e

Please sign in to comment.