mirror of https://github.com/openspug/spug
U 优化批量导入规则不允许主机名相同
parent
4daa6f80a2
commit
30c0dfe146
|
@ -97,7 +97,7 @@ def post_import(request):
|
||||||
password = request.POST.get('password')
|
password = request.POST.get('password')
|
||||||
file = request.FILES['file']
|
file = request.FILES['file']
|
||||||
ws = load_workbook(file, read_only=True)['Sheet1']
|
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):
|
for i, row in enumerate(ws.rows):
|
||||||
if i == 0: # 第1行是表头 略过
|
if i == 0: # 第1行是表头 略过
|
||||||
continue
|
continue
|
||||||
|
@ -127,6 +127,9 @@ def post_import(request):
|
||||||
except socket.error:
|
except socket.error:
|
||||||
summary['network'].append(i)
|
summary['network'].append(i)
|
||||||
continue
|
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)
|
host = Host.objects.create(created_by=request.user, **data)
|
||||||
if request.user.role:
|
if request.user.role:
|
||||||
request.user.role.add_host_perm(host.id)
|
request.user.role.add_host_perm(host.id)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class ComImport extends React.Component {
|
||||||
.then(res => {
|
.then(res => {
|
||||||
Modal.info({
|
Modal.info({
|
||||||
title: '导入结果',
|
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>
|
<Form.Item style={{margin: 0}} label="导入成功">{res.success.length}</Form.Item>
|
||||||
{res['fail'].length > 0 && <Form.Item style={{margin: 0, color: '#1890ff'}} label="验证失败">
|
{res['fail'].length > 0 && <Form.Item style={{margin: 0, color: '#1890ff'}} label="验证失败">
|
||||||
<Tooltip title={`相关行:${res['fail'].join(', ')}`}>{res['fail'].length}</Tooltip>
|
<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="无效数据">
|
{res['invalid'].length > 0 && <Form.Item style={{margin: 0, color: '#1890ff'}} label="无效数据">
|
||||||
<Tooltip title={`相关行:${res['invalid'].join(', ')}`}>{res['invalid'].length}</Tooltip>
|
<Tooltip title={`相关行:${res['invalid'].join(', ')}`}>{res['invalid'].length}</Tooltip>
|
||||||
</Form.Item>}
|
</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>
|
</Form>
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue