From 34031bfd6b21e4883bb3ef7291a1fcd76432b0ae Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Mon, 23 Nov 2015 23:55:19 +0800 Subject: [PATCH] fix bugs --- jasset/models.py | 2 +- jasset/views.py | 12 +++-- .../excels/cmdb_excel_2015_11_20_00_04.xlsx | Bin 0 -> 6125 bytes templates/jasset/asset_add.html | 46 +++++++++++++----- templates/jasset/asset_edit.html | 2 +- templates/jasset/error.html | 2 +- 6 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 static/files/excels/cmdb_excel_2015_11_20_00_04.xlsx diff --git a/jasset/models.py b/jasset/models.py index 4f0ce51079bc..c6cbe4cb5e23 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -57,7 +57,7 @@ class Asset(models.Model): """ asset modle """ - ip = models.GenericIPAddressField(blank=True, null=True, verbose_name=u"主机IP") + ip = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"主机IP") other_ip = models.CharField(max_length=255, blank=True, null=True, verbose_name=u"其他IP") hostname = models.CharField(unique=True, max_length=128, verbose_name=u"主机名") port = models.IntegerField(blank=True, null=True, verbose_name=u"端口号") diff --git a/jasset/views.py b/jasset/views.py index 54bc576a7a91..17f5a846804a 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -211,20 +211,21 @@ def asset_edit(request): password = request.POST.get('password', '') is_active = True if request.POST.get('is_active') == '1' else False use_default_auth = request.POST.get('use_default_auth', '') - try: asset_test = get_object(Asset, hostname=hostname) if asset_test and asset_id != unicode(asset_test.id): - error = u'该主机名 %s 已存在!' % hostname - raise ServerError(error) + emg = u'该主机名 %s 已存在!' % hostname + raise ServerError(emg) except ServerError: 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 = '' else: if password_old != password: password_encode = CRYPTOR.encrypt(password) @@ -237,9 +238,10 @@ def asset_edit(request): info = asset_diff(af_post.__dict__.get('initial'), request.POST) db_asset_alert(asset, username, info) - msg = u'主机 %s 修改成功' % ip + smg = u'主机 %s 修改成功' % ip else: emg = u'主机 %s 修改失败' % ip + return my_render('jasset/error.html', locals(), request) return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) return my_render('jasset/asset_edit.html', locals(), request) @@ -414,7 +416,7 @@ def asset_update(request): if not asset: return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) else: - asset_ansible_update(asset_list, name) + asset_ansible_update([asset], name) return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) diff --git a/static/files/excels/cmdb_excel_2015_11_20_00_04.xlsx b/static/files/excels/cmdb_excel_2015_11_20_00_04.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..05fc5eefcdcf615a97670bbb3e883e1f28f9b3e5 GIT binary patch literal 6125 zcmZ`-1yq!4*BxSD=$b)FQV@`qkdOvxhL)D@0ftTmqz0ss1}PB`kVd+@M5IeZTDm0v z(fi%sds*K%v)1#jch>APYxX|pyk{S%A{sgv004jhuK=!3M1i~96{r9}3l0E4hWymi zp3}n-Zs%fcVd3h+`TN4n;pt%i>b0Ru4i`9N_f&`Lqp^hMoRDq77y2qUODnN54NyB6 zBsDg3bxQf+$7_Lt&rQxtL-8bV>MpjCtfDb5a0#n?KPVk?@Nv@m zjGcKBUo>|7nA7Qj(fGEe$){^oyc7!=`WhauchV)QGJ0xo2WsQ*GPzUUDWsO~XQMwO z?7KL+Bm7$Djw_6R>d-}P4pry=ocB;eNJorsX9>=C@8mV^VwjP5&1+7kQl1bTSG%dl z?uV*BkMEHKhZ>~OSHcwN6~8i_IDvwB9FwNPqwQ)QoTclwHijqa5{ z^?H&BWc|)8d}wk&n>wSWERSNL+P9HRb$xrWS5rT?n2{k2X-vx>SPzbtjW1>+GyY27&?u-u(XhK@{SJHqn${2$K;pXxqb#;WYxF^^A~sOZ>AtI;wI6 z2tAdQ1a#?WOhPFcfF6kI9N}Y%zX@MVpQP|7^jV-r=n3Zc4&HO*wNmjBVmz7D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DvNWj15{6pr^DGH5rJ=OD|CIAQ7z zED9%Z!HT?k$(}cfI;U(a->Mv5J&Ow*cm(w4u@g@YmY+S)vgx;r_*vDqTIFi{0IxJm zE?86esVq>--|l4dp6D(Z}9kUnNlqCf+x!*4%^ri}=6lEEfiy^`h7GBY+V4_ep zr^pa{dVH?+AEeU|DAq{ixjo$*$$6grqC{iuwhbL#3%6&lW$U)(+1XEkA}yI)F=f2R z+mQN}Y?fCzyj?yX%6&X{x+i2~Xx=@;B_y*DoT;gU5`}Uk$d2#gkWs;P-`okT=+%^D z^I1&aP>3S+D_&CL{m7+`$txWwS)dV1Yi^wA-W-ymF_~5NP}U+VrTD?;We>S15T*H- z*}?5vDDM_iJ_CGi(U19DFWFos*$yKr*+I!of(kc$Ic@m*h;m5WrE94I@# zfi`cRiC47s9*na3Rc>d{&Te>&IPNPO%qZvWHLHQGA(2;`uhdVdaM_9}z`%jw(BamB zYa3?*Rve5_2238OJlwQZ%PS=Yg~Gn3XkCb0FNSyQ*&DZ-$I8hMqQL#C12&Q@BjX!k z?yXTrMWws0=Y20$Ul!I3i_g?EzPsWcVa3F(+E|%FP z&)9u|QQuobthAf{-a3+rk4Q!+{u-kGBIVce@b9I{-vs?~2-3S(*yX2s?!*c#u`VpZ z2D3+KFRN;l?B%U%ZLUsjH92>5mRUu)LeQEsoT{)zzrya-rFGXI|_fAf7Ce0$yU2ke0K z9{+9may!Cp)BY!d4RU(EZQ*aDZ@b4oXll?u(0_Z$+wj{)=?@%^^bo1|3CNNhTb0O{y?RXp5ea?c(()GZW(_9Fd|LgKN`qw;O)x#0~A0e7xI_?N1Z_x Ufk;UJ0Bq#@1u{2uAiwVZ51tE?YybcN literal 0 HcmV?d00001 diff --git a/templates/jasset/asset_add.html b/templates/jasset/asset_add.html index 35903a4696d8..807dcd1305c7 100644 --- a/templates/jasset/asset_add.html +++ b/templates/jasset/asset_add.html @@ -55,7 +55,7 @@
填写资产基本信息
@@ -142,26 +142,46 @@
填写资产基本信息
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: { -{# "ip": {#} -{# rule: "required;check_ip",#} -{# tip: "输入IP",#} -{# ok: "",#} -{# msg: {required: "必须填写!"}#} -{# },#} + "ip": { + rule: "check_ip;", + tip: "输入IP", + ok: "", + msg: {required: "必须填写!"} + }, "hostname": { rule: "required", tip: "填写主机名", 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_edit.html b/templates/jasset/asset_edit.html index ff9552d4a794..1ec1b8ef2088 100644 --- a/templates/jasset/asset_edit.html +++ b/templates/jasset/asset_edit.html @@ -55,7 +55,7 @@
修改资产基本信息
diff --git a/templates/jasset/error.html b/templates/jasset/error.html index 4fa2142452a1..3ad1bf040e59 100644 --- a/templates/jasset/error.html +++ b/templates/jasset/error.html @@ -1,4 +1,4 @@ -{% for field in af %} +{% for field in af_form %}
{{ field.errors }}
{{ field.label_tag }}: {{ field }} {% endfor %}