From 85f4a7405994fcab93e3f5bff2fb3175302e28bf Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Mon, 13 May 2024 11:21:03 +0200 Subject: [PATCH 1/2] Fix DELETE call query params --- sqladmin/application.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sqladmin/application.py b/sqladmin/application.py index 41397acf..e660e67f 100644 --- a/sqladmin/application.py +++ b/sqladmin/application.py @@ -16,14 +16,14 @@ cast, no_type_check, ) -from urllib.parse import urljoin +from urllib.parse import parse_qsl, urljoin from jinja2 import ChoiceLoader, FileSystemLoader, PackageLoader from sqlalchemy.engine import Engine from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import Session, sessionmaker from starlette.applications import Starlette -from starlette.datastructures import URL, FormData, UploadFile +from starlette.datastructures import URL, FormData, MultiDict, UploadFile from starlette.exceptions import HTTPException from starlette.middleware import Middleware from starlette.requests import Request @@ -493,7 +493,10 @@ async def delete(self, request: Request) -> Response: await model_view.delete_model(request, pk) - return Response(content=str(request.url_for("admin:list", identity=identity))) + referer_url = URL(request.headers.get("referer", "")) + referer_params = MultiDict(parse_qsl(referer_url.query)) + url = URL(str(request.url_for("admin:list", identity=identity))).include_query_params(**referer_params) + return Response(content=str(url)) @login_required async def create(self, request: Request) -> Response: From b72d4b2f79fc42f77cac50b135514b5b781aa754 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Mon, 13 May 2024 11:26:10 +0200 Subject: [PATCH 2/2] Update application.py --- sqladmin/application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sqladmin/application.py b/sqladmin/application.py index e660e67f..93a8e996 100644 --- a/sqladmin/application.py +++ b/sqladmin/application.py @@ -495,7 +495,8 @@ async def delete(self, request: Request) -> Response: referer_url = URL(request.headers.get("referer", "")) referer_params = MultiDict(parse_qsl(referer_url.query)) - url = URL(str(request.url_for("admin:list", identity=identity))).include_query_params(**referer_params) + url = URL(str(request.url_for("admin:list", identity=identity))) + url = url.include_query_params(**referer_params) return Response(content=str(url)) @login_required