From 6f8bae8d5ced721319250178351a0986f377f89a Mon Sep 17 00:00:00 2001 From: lxy <46486798@qq.com> Date: Mon, 8 Jul 2024 09:33:51 +0000 Subject: [PATCH] =?UTF-8?q?update=20backend/dvadmin/utils/middleware.py.?= =?UTF-8?q?=20=E5=BD=93=E5=90=8C=E4=B8=80=E6=97=B6=E5=88=BB=E8=BF=9B?= =?UTF-8?q?=E6=9D=A5=E5=A4=9A=E4=B8=AA=E8=AF=B7=E6=B1=82=E4=B8=94=E9=83=BD?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=AE=8C=E6=88=90=E5=93=8D=E5=BA=94=E6=97=B6?= =?UTF-8?q?=EF=BC=8Coperation=5Flog=5Fid=E4=BC=9A=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E8=BF=9B=E6=9D=A5=E7=9A=84?= =?UTF-8?q?ID=EF=BC=8C=E5=AF=BC=E8=87=B4=E4=B9=8B=E5=89=8D=E6=8C=89?= =?UTF-8?q?=E8=BF=9B=E6=9D=A5=E7=9A=84=E8=AF=B7=E6=B1=82=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=88=B0=E5=90=8C=E4=B8=80=E4=B8=AAid=E4=B8=8A=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lxy <46486798@qq.com> --- backend/dvadmin/utils/middleware.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/dvadmin/utils/middleware.py b/backend/dvadmin/utils/middleware.py index f4717a4..6029c5a 100644 --- a/backend/dvadmin/utils/middleware.py +++ b/backend/dvadmin/utils/middleware.py @@ -32,6 +32,14 @@ class ApiLoggingMiddleware(MiddlewareMixin): request.request_path = get_request_path(request) def __handle_response(self, request, response): + + # 判断有无log_id属性,使用All记录时,会出现此情况 + if request.request_data.get('log_id', None) is None: + return + + # 移除log_id,不记录此ID + log_id = request.request_data.pop('log_id') + # request_data,request_ip由PermissionInterfaceMiddleware中间件中添加的属性 body = getattr(request, 'request_data', {}) # 请求含有password则用*替换掉(暂时先用于所有接口的password请求参数) @@ -60,7 +68,7 @@ class ApiLoggingMiddleware(MiddlewareMixin): 'status': True if response.data.get('code') in [2000, ] else False, 'json_result': {"code": response.data.get('code'), "msg": response.data.get('msg')}, } - operation_log, creat = OperationLog.objects.update_or_create(defaults=info, id=self.operation_log_id) + operation_log, creat = OperationLog.objects.update_or_create(defaults=info, id=log_id) if not operation_log.request_modular and settings.API_MODEL_MAP.get(request.request_path, None): operation_log.request_modular = settings.API_MODEL_MAP[request.request_path] operation_log.save() @@ -71,7 +79,8 @@ class ApiLoggingMiddleware(MiddlewareMixin): if self.methods == 'ALL' or request.method in self.methods: log = OperationLog(request_modular=get_verbose_name(view_func.cls.queryset)) log.save() - self.operation_log_id = log.id + # self.operation_log_id = log.id + request.request_data['log_id'] = log.id return