Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
halcyonone committed Nov 23, 2015
1 parent 5a3c11f commit 34031bf
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion jasset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"端口号")
Expand Down
12 changes: 7 additions & 5 deletions jasset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)


Expand Down
Binary file not shown.
46 changes: 33 additions & 13 deletions templates/jasset/asset_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h5> 填写资产基本信息 </h5>
<div class="col-sm-2">
<div class="radio i-checks">
<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>
</div>
</div>
Expand Down Expand Up @@ -142,26 +142,46 @@ <h5> 填写资产基本信息 </h5>
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();
Expand Down
2 changes: 1 addition & 1 deletion templates/jasset/asset_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h5> 修改资产基本信息 </h5>
<div class="col-sm-2">
<div class="radio i-checks">
<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>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/jasset/error.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% for field in af %}
{% for field in af_form %}
<div class="alert alert-warning text-center"> {{ field.errors }}</div>
{{ field.label_tag }}: {{ field }}
{% endfor %}
Expand Down

0 comments on commit 34031bf

Please sign in to comment.