diff --git a/spug_api/apps/alarm/views.py b/spug_api/apps/alarm/views.py index e1737ca..0ff1309 100644 --- a/spug_api/apps/alarm/views.py +++ b/spug_api/apps/alarm/views.py @@ -40,7 +40,7 @@ class GroupView(View): Argument('id', type=int, help='请指定操作对象') ).parse(request.GET) if error is None: - detection = Detection.objects.filter(notify_grp__regex=fr'\D{form.id}\D').first() + detection = Detection.objects.filter(notify_grp__regex=fr'[^0-9]{form.id}[^0-9]').first() if detection: return json_response(error=f'监控任务【{detection.name}】正在使用该报警组,请解除关联后再尝试删除该联系组') Group.objects.filter(pk=form.id).delete() diff --git a/spug_api/apps/host/views.py b/spug_api/apps/host/views.py index e4cfbc3..70e5ca8 100644 --- a/spug_api/apps/host/views.py +++ b/spug_api/apps/host/views.py @@ -75,19 +75,19 @@ class HostView(View): Argument('id', type=int, help='请指定操作对象') ).parse(request.GET) if error is None: - deploy = Deploy.objects.filter(host_ids__regex=fr'\D{form.id}\D').annotate( + deploy = Deploy.objects.filter(host_ids__regex=fr'[^0-9]{form.id}[^0-9]').annotate( app_name=F('app__name'), env_name=F('env__name') ).first() if deploy: return json_response(error=f'应用【{deploy.app_name}】在【{deploy.env_name}】的发布配置关联了该主机,请解除关联后再尝试删除该主机') - task = Task.objects.filter(targets__regex=fr'\D{form.id}\D').first() + task = Task.objects.filter(targets__regex=fr'[^0-9]{form.id}[^0-9]').first() if task: return json_response(error=f'任务计划中的任务【{task.name}】关联了该主机,请解除关联后再尝试删除该主机') detection = Detection.objects.filter(type__in=('3', '4'), addr=form.id).first() if detection: return json_response(error=f'监控中心的任务【{detection.name}】关联了该主机,请解除关联后再尝试删除该主机') - role = Role.objects.filter(host_perms__regex=fr'\D{form.id}\D').first() + role = Role.objects.filter(host_perms__regex=fr'[^0-9]{form.id}[^0-9]').first() if role: return json_response(error=f'角色【{role.name}】的主机权限关联了该主机,请解除关联后再尝试删除该主机') Host.objects.filter(pk=form.id).update(