pull/26/head
halcyon 9 years ago
parent 5a3c11f619
commit 34031bfd6b

@ -57,7 +57,7 @@ class Asset(models.Model):
""" """
asset modle 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") 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"主机名") hostname = models.CharField(unique=True, max_length=128, verbose_name=u"主机名")
port = models.IntegerField(blank=True, null=True, verbose_name=u"端口号") port = models.IntegerField(blank=True, null=True, verbose_name=u"端口号")

@ -211,20 +211,21 @@ def asset_edit(request):
password = request.POST.get('password', '') password = request.POST.get('password', '')
is_active = True if request.POST.get('is_active') == '1' else False is_active = True if request.POST.get('is_active') == '1' else False
use_default_auth = request.POST.get('use_default_auth', '') use_default_auth = request.POST.get('use_default_auth', '')
try: try:
asset_test = get_object(Asset, hostname=hostname) asset_test = get_object(Asset, hostname=hostname)
if asset_test and asset_id != unicode(asset_test.id): if asset_test and asset_id != unicode(asset_test.id):
error = u'该主机名 %s 已存在!' % hostname emg = u'该主机名 %s 已存在!' % hostname
raise ServerError(error) raise ServerError(emg)
except ServerError: except ServerError:
pass pass
else: else:
if af_post.is_valid(): if af_post.is_valid():
print 'hehe', af_post
af_save = af_post.save(commit=False) af_save = af_post.save(commit=False)
if use_default_auth: if use_default_auth:
af_save.username = '' af_save.username = ''
af_save.password = '' af_save.password = ''
af_save.port = ''
else: else:
if password_old != password: if password_old != password:
password_encode = CRYPTOR.encrypt(password) password_encode = CRYPTOR.encrypt(password)
@ -237,9 +238,10 @@ def asset_edit(request):
info = asset_diff(af_post.__dict__.get('initial'), request.POST) info = asset_diff(af_post.__dict__.get('initial'), request.POST)
db_asset_alert(asset, username, info) db_asset_alert(asset, username, info)
msg = u'主机 %s 修改成功' % ip smg = u'主机 %s 修改成功' % ip
else: else:
emg = u'主机 %s 修改失败' % ip emg = u'主机 %s 修改失败' % ip
return my_render('jasset/error.html', locals(), request)
return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id)
return my_render('jasset/asset_edit.html', locals(), request) return my_render('jasset/asset_edit.html', locals(), request)
@ -414,7 +416,7 @@ def asset_update(request):
if not asset: if not asset:
return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id)
else: else:
asset_ansible_update(asset_list, name) asset_ansible_update([asset], name)
return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id)

@ -55,7 +55,7 @@
<div class="col-sm-2"> <div class="col-sm-2">
<div class="radio i-checks"> <div class="radio i-checks">
<label> <label>
<input type="checkbox" checked="" id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span> <input type="checkbox" checked="checked" id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span>
</label> </label>
</div> </div>
</div> </div>
@ -142,26 +142,46 @@
rules: { 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_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}$/, '端口号不正确'], 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: { fields: {
{# "ip": {#} "ip": {
{# rule: "required;check_ip",#} rule: "check_ip;",
{# tip: "输入IP",#} tip: "输入IP",
{# ok: "",#} ok: "",
{# msg: {required: "必须填写!"}#} msg: {required: "必须填写!"}
{# },#} },
"hostname": { "hostname": {
rule: "required", rule: "required",
tip: "填写主机名", tip: "填写主机名",
ok: "", ok: "",
msg: {required: "必须填写!"} msg: {required: "必须填写!"}
}, },
{# "port": {#} "port": {
{# rule: "required;check_port",#} rule: "required(use_default_auth)",
{# tip: "输入端口号",#} tip: "输入端口号",
{# ok: "",#} ok: "",
{# msg: {required: "必须填写!"}#} 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) { valid: function(form) {
form.submit(); form.submit();

@ -55,7 +55,7 @@
<div class="col-sm-2"> <div class="col-sm-2">
<div class="radio i-checks"> <div class="radio i-checks">
<label> <label>
<input type="checkbox" {% if asset.use_default_auth %} checked="" {% endif %} id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span> <input type="checkbox" {% if asset.use_default_auth %} checked="checked" {% endif %} id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span>
</label> </label>
</div> </div>
</div> </div>

@ -1,4 +1,4 @@
{% for field in af %} {% for field in af_form %}
<div class="alert alert-warning text-center"> {{ field.errors }}</div> <div class="alert alert-warning text-center"> {{ field.errors }}</div>
{{ field.label_tag }}: {{ field }} {{ field.label_tag }}: {{ field }}
{% endfor %} {% endfor %}

Loading…
Cancel
Save