add update all button

pull/26/head
wangyong 2015-11-24 11:20:01 +08:00
parent dd4c243d7c
commit 99439be04f
3 changed files with 58 additions and 21 deletions

View File

@ -130,6 +130,7 @@ def asset_add(request):
af = AssetForm()
if request.method == 'POST':
af_post = AssetForm(request.POST)
print af_post
ip = request.POST.get('ip', '')
hostname = request.POST.get('hostname', '')
is_active = True if request.POST.get('is_active') == '1' else False
@ -220,12 +221,11 @@ def asset_edit(request):
pass
else:
if af_post.is_valid():
print 'hehe', af_post
af_save = af_post.save(commit=False)
if use_default_auth:
af_save.username = ''
af_save.password = ''
af_save.port = ''
af_save.port = None
else:
if password_old != password:
password_encode = CRYPTOR.encrypt(password)
@ -423,14 +423,18 @@ def asset_update(request):
@require_role('admin')
def asset_update_batch(request):
if request.method == 'POST':
asset_list = []
arg = request.GET.get('arg', '')
name = unicode(request.user.username) + ' - ' + u'自动更新'
asset_id_all = unicode(request.POST.get('asset_id_all', ''))
asset_id_all = asset_id_all.split(',')
for asset_id in asset_id_all:
asset = get_object(Asset, id=asset_id)
if asset:
asset_list.append(asset)
if arg == 'all':
asset_list = Asset.objects.all()
else:
asset_list = []
asset_id_all = unicode(request.POST.get('asset_id_all', ''))
asset_id_all = asset_id_all.split(',')
for asset_id in asset_id_all:
asset = get_object(Asset, id=asset_id)
if asset:
asset_list.append(asset)
asset_ansible_update(asset_list, name)
return HttpResponse(u'批量更新成功!')
return HttpResponse(u'批量更新成功!')

View File

@ -186,12 +186,20 @@
$('label[for="' + field + '"]').parent().addClass("required");
});
$('#assetForm').validator({
$('#assetForm').validator({
timely: 2,
theme: "yellow_right_effect",
rules: {
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
check_port: [/^\d{1,5}$/, '端口号不正确'],
use_default_auth: function() {
var str1 = $("#id_use_default_auth").is(":checked");
if (str1 == true){
var decide = false;
} else {
var decide = true;
}
return decide}
},
fields: {
"hostname": {
@ -200,17 +208,24 @@
ok: "",
msg: {required: "必须填写!"}
},
{# "ip": {#}
{# rule: "required;check_ip",#}
{# tip: "输入IP",#}
{# ok: "",#}
{# msg: {required: "必须填写!"}#}
{# },#}
{# "port": {#}
{# rule: "required;check_port",#}
{# tip: "输入端口号",#}
{# ok: "",#}
{# msg: {required: "必须填写!"}#}
"port": {
rule: "required(use_default_auth)",
tip: "输入端口号",
ok: "",
msg: {required: "必须填写!"}
},
"username": {
rule: "required(use_default_auth)",
tip: "输入用户名",
ok: "",
msg: {required: "必须填写!"}
},
"password": {
rule: "required(use_default_auth)",
tip: "输入密码",
ok: "",
msg: {required: "必须填写!"}
}
},
valid: function(form) {
form.submit();

View File

@ -142,6 +142,7 @@
<input type="button" id="asset_del" class="btn btn-danger btn-sm" name="del_button" value="删除"/>
<a value="/jasset/asset_edit_batch/" type="button" class="btn btn-sm btn-warning iframe">修改</a>
<input type="button" id="asset_update" class="btn btn-info btn-sm" name="update_button" value="更新"/>
<input type="button" id="asset_update_all" class="btn btn-primary btn-sm" name="update_button" value="更新全部"/>
</div>
{% include 'paginator.html' %}
</div>
@ -241,6 +242,23 @@
});
});
{# function update_tips(){#}
{# layer.tips('我是另外一个tips只不过我长得跟之前那位稍有些不一样。', '吸附元素选择器', {#}
{# tips: [1, '#3595CC'],#}
{# time: 4000#}
{# });#}
{# }#}
$('#asset_update_all').click(function () {
layer.msg('玩命更新中...', {time: 200000});
$.ajax({
type: "post",
url: "/jasset/asset_update_batch/?arg=all",
success: function () {
parent.location.reload();
}
});
});
function change_info(){
var args = $("#asset_form").serialize();