diff --git a/jasset/views.py b/jasset/views.py index 17f5a8468..38a7d2a3a 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -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'批量更新成功!') diff --git a/templates/jasset/asset_edit.html b/templates/jasset/asset_edit.html index 1ec1b8ef2..a3f9bd516 100644 --- a/templates/jasset/asset_edit.html +++ b/templates/jasset/asset_edit.html @@ -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(); diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html index fe03cc1a2..2c8291b01 100644 --- a/templates/jasset/asset_list.html +++ b/templates/jasset/asset_list.html @@ -142,6 +142,7 @@ 修改 + {% include 'paginator.html' %} @@ -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();