U 优化批量导入规则不允许主机名相同

pull/137/head
vapao 2020-06-13 09:58:18 +08:00
parent 4daa6f80a2
commit 30c0dfe146
2 changed files with 8 additions and 2 deletions

View File

@ -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)

View File

@ -29,7 +29,7 @@ class ComImport extends React.Component {
.then(res => {
Modal.info({
title: '导入结果',
content: <Form labelCol={{span: 5}} wrapperCol={{span: 14}}>
content: <Form labelCol={{span: 7}} wrapperCol={{span: 14}}>
<Form.Item style={{margin: 0}} label="导入成功">{res.success.length}</Form.Item>
{res['fail'].length > 0 && <Form.Item style={{margin: 0, color: '#1890ff'}} label="验证失败">
<Tooltip title={`相关行:${res['fail'].join(', ')}`}>{res['fail'].length}</Tooltip>
@ -43,6 +43,9 @@ class ComImport extends React.Component {
{res['invalid'].length > 0 && <Form.Item style={{margin: 0, color: '#1890ff'}} label="无效数据">
<Tooltip title={`相关行:${res['invalid'].join(', ')}`}>{res['invalid'].length}</Tooltip>
</Form.Item>}
{res['repeat'].length > 0 && <Form.Item style={{margin: 0, color: '#1890ff'}} label="重复主机名">
<Tooltip title={`相关行:${res['repeat'].join(', ')}`}>{res['repeat'].length}</Tooltip>
</Form.Item>}
</Form>
})
})