mirror of https://github.com/jumpserver/jumpserver
idc
parent
2e254af935
commit
a4bd352486
|
@ -427,34 +427,46 @@ def idc_list(request):
|
|||
@require_super_user
|
||||
def idc_edit(request):
|
||||
header_title, path1, path2 = u'编辑IDC', u'资产管理', u'编辑IDC'
|
||||
edit = 1
|
||||
idc_id = request.GET.get('id')
|
||||
j_idc = IDC.objects.get(id=idc_id)
|
||||
default = IDC.objects.get(name='默认').asset_set.all()
|
||||
eposts = contact_list = Asset.objects.filter(idc=j_idc).order_by('ip')
|
||||
posts = [g for g in default if g not in eposts]
|
||||
idc = IDC.objects.filter(id=idc_id)
|
||||
if idc:
|
||||
idc = idc[0]
|
||||
default = IDC.objects.get(name='默认').asset_set.all()
|
||||
eposts = Asset.objects.filter(idc=idc).order_by('ip')
|
||||
posts = [g for g in default if g not in eposts]
|
||||
else:
|
||||
emg = '此IDC不存在'
|
||||
|
||||
if request.method == 'POST':
|
||||
j_group = request.POST.get('j_idc')
|
||||
idc_id = request.POST.get('id')
|
||||
j_idc = request.POST.get('j_idc')
|
||||
j_hosts = request.POST.getlist('j_hosts')
|
||||
j_comment = request.POST.get('j_comment')
|
||||
idc_default = request.POST.getlist('idc_default')
|
||||
|
||||
for host in j_hosts:
|
||||
g = Asset.objects.get(id=host)
|
||||
Asset.objects.filter(id=host).update(idc=j_idc)
|
||||
idc = IDC.objects.filter(id=idc_id)
|
||||
if idc:
|
||||
idc.update(name=j_idc, comment=j_comment)
|
||||
for host in j_hosts:
|
||||
g = Asset.objects.get(id=host)
|
||||
Asset.objects.filter(id=host).update(idc=idc)
|
||||
|
||||
for host in idc_default:
|
||||
g = Asset.objects.get(id=host)
|
||||
i = IDC.objects.get(name='默认')
|
||||
Asset.objects.filter(id=host).update(idc=i)
|
||||
for host in idc_default:
|
||||
g = Asset.objects.get(id=host)
|
||||
i = IDC.objects.get(name='默认')
|
||||
Asset.objects.filter(id=host).update(idc=i)
|
||||
else:
|
||||
emg = '此IDC不存在'
|
||||
return render_to_response('jasset/idc_edit.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
return HttpResponseRedirect('/jasset/idc_list/' % idc_id)
|
||||
return HttpResponseRedirect('/jasset/idc_list/?id=%s' % idc_id)
|
||||
|
||||
return render_to_response('jasset/idc_add.html', locals(), context_instance=RequestContext(request))
|
||||
return render_to_response('jasset/idc_edit.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@require_super_user
|
||||
def idc_del(request, offset):
|
||||
def idc_del(request):
|
||||
offset = request.GET.get('id', '')
|
||||
if offset == 'multi':
|
||||
len_list = request.POST.get("len_list")
|
||||
for i in range(int(len_list)):
|
||||
|
|
|
@ -35,43 +35,14 @@
|
|||
{% endif %}
|
||||
<form id="assetForm" method="post" class="form-horizontal">
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> IDC名 <span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8"><input type="text" value="{{ j_idc.name }}" placeholder="北京联通" name="j_idc" class="form-control"></div>
|
||||
<div class="col-sm-8"><input type="text" value="{{ idc.name }}" placeholder="北京联通" name="j_idc" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
|
||||
<div class="col-sm-8"><input type="text" value="{{ j_idc.comment }}" placeholder="核心联通机房" name="j_comment" class="form-control"></div>
|
||||
<div class="col-sm-8"><input type="text" value="{{ idc.comment }}" placeholder="核心联通机房" name="j_comment" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
{% if edit %}
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="groups" class="col-lg-2 control-label">主机</label>
|
||||
<div class="col-sm-3">
|
||||
<select id="groups" name="idc_default" size="12" class="form-control m-b" multiple>
|
||||
{% for post in posts %}
|
||||
<option value="{{ post.id }}">{{ post.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 50px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('groups', 'groups_selected')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move_left('groups_selected', 'groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="groups_selected" name="j_hosts" class="form-control m-b" size="12" multiple>
|
||||
{% for post in eposts %}
|
||||
<option value="{{ post.id }}">{{ post.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-5">
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{% include 'nav_cat_bar.html' %}
|
||||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-10">
|
||||
<div class="ibox float-e-margins">
|
||||
<div id="ibox-content" class="ibox-title">
|
||||
<h5> 填写IDC基本信息 </h5>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapse-link">
|
||||
<i class="fa fa-chevron-up"></i>
|
||||
</a>
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<i class="fa fa-wrench"></i>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-user">
|
||||
<li><a href="#">未启用 1</a>
|
||||
</li>
|
||||
<li><a href="#">未启用 2</a>
|
||||
</li>
|
||||
</ul>
|
||||
<a class="close-link">
|
||||
<i class="fa fa-times"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ibox-content">
|
||||
{% if emg %}
|
||||
<div class="alert alert-warning text-center">{{ emg }}</div>
|
||||
{% endif %}
|
||||
{% if smg %}
|
||||
<div class="alert alert-success text-center">{{ smg }}</div>
|
||||
{% endif %}
|
||||
<form id="assetForm" method="post" class="form-horizontal">
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> IDC名 <span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<input name="id" type="text" value="{{ idc.id }}" style="display: none;">
|
||||
<input type="text" value="{{ idc.name }}" placeholder="北京联通" name="j_idc" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
|
||||
<div class="col-sm-8"><input type="text" value="{{ idc.comment }}" placeholder="核心联通机房" name="j_comment" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="groups" class="col-lg-2 control-label">主机</label>
|
||||
<div class="col-sm-3">
|
||||
<select id="groups" name="idc_default" size="12" class="form-control m-b" multiple>
|
||||
{% for post in posts %}
|
||||
<option value="{{ post.id }}">{{ post.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 50px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('groups', 'groups_selected')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move_left('groups_selected', 'groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="groups_selected" name="j_hosts" class="form-control m-b" size="12" multiple>
|
||||
{% for post in eposts %}
|
||||
<option value="{{ post.id }}">{{ post.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-5">
|
||||
<button class="btn btn-white" type="submit"> 重置 </button>
|
||||
<button class="btn btn-primary" type="sumbit"> 提交 </button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$('#assetForm').validator({
|
||||
timely: 2,
|
||||
theme: "yellow_right_effect",
|
||||
fields: {
|
||||
"j_idc": {
|
||||
rule: "required",
|
||||
tip: "输入IDC名",
|
||||
ok: "",
|
||||
msg: {required: "IDC名必须填写!"},
|
||||
data: {'data-ok':"主机名可以使用", 'data-msg-required': '主机名已正确'}
|
||||
}
|
||||
},
|
||||
valid: function(form) {
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
|
@ -55,7 +55,7 @@
|
|||
<a href="/jasset/idc_detail/?id={{ post.id }}" class="iframe btn btn-xs btn-primary">详情</a>
|
||||
{% ifequal session_role_id 2 %}
|
||||
<a href="/jasset/idc_edit/?id={{ post.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="/jasset/idc_del/{{ post.id }}" class="btn btn-xs btn-danger">删除</a>
|
||||
<a href="/jasset/idc_del/?id={{ post.id }}" class="btn btn-xs btn-danger">删除</a>
|
||||
{% endifequal %}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -92,7 +92,7 @@
|
|||
if (confirm("确定删除")) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/jasset/idc_del/multi/",
|
||||
url: "/jasset/idc_del/?id=multi",
|
||||
data: {"id_list": id_list, "len_list": j},
|
||||
success: function (data) {
|
||||
window.open("/jasset/idc_list/", "_self");
|
||||
|
|
Loading…
Reference in New Issue