From 30c0dfe146fd5c273e8411b901b3a374fc333d2d Mon Sep 17 00:00:00 2001 From: vapao Date: Sat, 13 Jun 2020 09:58:18 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E8=A7=84=E5=88=99=E4=B8=8D=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E5=90=8D=E7=9B=B8=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/host/views.py | 5 ++++- spug_web/src/pages/host/Import.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spug_api/apps/host/views.py b/spug_api/apps/host/views.py index cf90cf1..0d905f7 100644 --- a/spug_api/apps/host/views.py +++ b/spug_api/apps/host/views.py @@ -97,7 +97,7 @@ def post_import(request): password = request.POST.get('password') file = request.FILES['file'] ws = load_workbook(file, read_only=True)['Sheet1'] - summary = {'invalid': [], 'skip': [], 'fail': [], 'network': [], 'success': []} + summary = {'invalid': [], 'skip': [], 'fail': [], 'network': [], 'repeat': [], 'success': []} for i, row in enumerate(ws.rows): if i == 0: # 第1行是表头 略过 continue @@ -127,6 +127,9 @@ def post_import(request): except socket.error: summary['network'].append(i) continue + if Host.objects.filter(name=data.name, deleted_by_id__isnull=True).exists(): + summary['repeat'].append(i) + continue host = Host.objects.create(created_by=request.user, **data) if request.user.role: request.user.role.add_host_perm(host.id) diff --git a/spug_web/src/pages/host/Import.js b/spug_web/src/pages/host/Import.js index c9169b3..07773f2 100644 --- a/spug_web/src/pages/host/Import.js +++ b/spug_web/src/pages/host/Import.js @@ -29,7 +29,7 @@ class ComImport extends React.Component { .then(res => { Modal.info({ title: '导入结果', - content:
+ content: {res.success.length} {res['fail'].length > 0 && {res['fail'].length} @@ -43,6 +43,9 @@ class ComImport extends React.Component { {res['invalid'].length > 0 && {res['invalid'].length} } + {res['repeat'].length > 0 && + {res['repeat'].length} + } }) })