diff --git a/jasset/asset_api.py b/jasset/asset_api.py index 9cc375509..0034f6495 100644 --- a/jasset/asset_api.py +++ b/jasset/asset_api.py @@ -69,33 +69,6 @@ def db_asset_add(**kwargs): asset.group = group_select -# -# def get_host_groups(groups): -# """ 获取主机所属的组类 """ -# ret = [] -# for group_id in groups: -# group = BisGroup.objects.filter(id=group_id) -# if group: -# group = group[0] -# ret.append(group) -# group_all = get_object_or_404(BisGroup, name='ALL') -# ret.append(group_all) -# return ret -# -# -# # def get_host_depts(depts): -# # """ 获取主机所属的部门类 """ -# # ret = [] -# # for dept_id in depts: -# # dept = DEPT.objects.filter(id=dept_id) -# # if dept: -# # dept = dept[0] -# # ret.append(dept) -# # return ret -# -# - - def db_asset_update(**kwargs): """ 修改主机时数据库操作函数 """ asset_id = kwargs.pop('id') diff --git a/jasset/models.py b/jasset/models.py index c6cbe4cb5..b3765fbe4 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -16,9 +16,13 @@ ASSET_STATUS = ( ) ASSET_TYPE = ( - (1, u"服务器"), - (2, u"网络设备"), - (3, u"其他") + (1, u"物理机"), + (2, u"虚拟机"), + (3, u"交换机"), + (4, u"路由器"), + (5, u"防火墙"), + (6, u"Docker"), + (7, u"其他") ) diff --git a/jasset/views.py b/jasset/views.py index 38a7d2a3a..dff5621d8 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -128,9 +128,10 @@ def asset_add(request): header_title, path1, path2 = u'添加资产', u'资产管理', u'添加资产' asset_group_all = AssetGroup.objects.all() af = AssetForm() + default_setting = get_object(Setting, name='default') + default_port = default_setting.field2 if default_setting else '' 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 @@ -147,7 +148,7 @@ def asset_add(request): asset_save = af_post.save(commit=False) if not use_default_auth: password = request.POST.get('password', '') - password_encode = password + password_encode = CRYPTOR.encrypt(password) asset_save.password = password_encode if not ip: asset_save.ip = hostname @@ -227,9 +228,11 @@ def asset_edit(request): af_save.password = '' af_save.port = None else: - if password_old != password: + if password: password_encode = CRYPTOR.encrypt(password) af_save.password = password_encode + else: + af_save.password = password_old af_save.is_active = True if is_active else False af_save.save() af_post.save_m2m() @@ -266,6 +269,7 @@ def asset_list(request): export = request.GET.get("export", False) group_id = request.GET.get("group_id", '') idc_id = request.GET.get("idc_id", '') + asset_id_all = request.GET.getlist("id", '') if group_id: group = get_object(AssetGroup, id=group_id) if group: @@ -302,6 +306,12 @@ def asset_list(request): Q(disk__contains=keyword)) if export: + if asset_id_all: + asset_find = [] + for asset_id in asset_id_all: + asset = get_object(Asset, id=asset_id) + if asset: + asset_find.append(asset) s = write_excel(asset_find) if s[0]: file_name = s[1] diff --git a/static/files/excels/asset.xlsx b/static/files/excels/asset.xlsx deleted file mode 100644 index 1b92db891..000000000 Binary files a/static/files/excels/asset.xlsx and /dev/null differ 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 deleted file mode 100644 index 05fc5eefc..000000000 Binary files a/static/files/excels/cmdb_excel_2015_11_20_00_04.xlsx and /dev/null differ diff --git a/templates/jasset/asset_add.html b/templates/jasset/asset_add.html index 807dcd130..210d583d4 100644 --- a/templates/jasset/asset_add.html +++ b/templates/jasset/asset_add.html @@ -74,11 +74,11 @@ -
-