#_*_coding:utf-8_*_
__author__ = 'jidong'
from django.db.models import Q
# Create your views here.
from itam.api import *
from iasset import models
from iasset.forms import *
from info.models import ProductModel,Contract
from iuser.models import User
from iservice.models import ServiceInfo
from ilog.models import EventLog
from inetwork.models import IPAddress, Ports
import copy
@require_role(role='user')
def asset_index(request):
"""
资产列表首页
"""
header_title, path1, path2 = u'资产列表', u'资产', u'列表'
idc_all = models.IDC.objects.all()
asset_types = models.ASSET_TYPE_CHOICES
asset_status = models.DEVICE_STATUS
return my_render('iasset/asset/list.html', locals(), request)
def asset_list(request):
"""
资产列表
:param request:
:return:
"""
asset_obj_all = models.Asset.objects.all()
asset_obj = asset_obj_all
# 所有对象, 分页器, 本页对象, 所有页码, 本页页码,是否显示第一页,是否显示最后一页
contacts_all, paginator, rows, page_range, current_page, show_first, show_end = pages(asset_obj, request)
total = asset_obj.count()
rows_list = []
for r in rows.object_list:
r_dict = class_to_dict(r)
asset_select = models.Asset.objects.get(id=r_dict['id'])
r_dict['asset_type'] = ProductModel.objects.get(id=asset_select.model_id).get_asset_type_display()
r_dict['asset_type_key'] = ProductModel.objects.get(id=asset_select.model_id).asset_type
r_dict['status'] = asset_select.get_status_display()
r_dict['ip'] = ''
ports = asset_select.ports_set.all()
if ports.count() > 0:
for i in ports:
r_dict['ip'] += str(i.ip.ipaddress) + ';'
cabinet_obj = get_device_attr(asset_select, r_dict['asset_type_key'], "cabinet")
if cabinet_obj != '' and cabinet_obj != None:
r_dict['cabinet'] = cabinet_obj.location
r_dict['idc'] = cabinet_obj.idc.name
else:
r_dict['cabinet'] = ''
service_obj = get_device_attr(asset_select, r_dict['asset_type_key'], "service")
# print service_obj
if service_obj != '' and service_obj != None:
r_dict['service'] = service_obj.name
else:
r_dict['service'] = ''
rows_list.append(r_dict)
print "rows_list:",rows_list
return HttpResponse(json.dumps({'total': total, 'rows': rows_list}, cls=DatetimeEncoder))
# def get_cabinet(asset_obj,asset_type):
# """
# 根据资产名称返回机柜对象
# """
# asset_obj = asset_obj
# asset_type = asset_type
# if asset_type not in ["parts"]:
# cabinet = eval("asset_obj.%s.cabinet" % asset_type)
# return cabinet
# else:
# return ''
def get_device_attr(asset_obj,asset_type,attribute):
"""
根据设备对象返回设备属性
"""
# asset_obj = asset_obj
# asset_type = asset_type
# attr = attribute
# if asset_type not in ["parts"]:
# ret = eval("asset_obj.%s.%s" % (asset_type,attribute))
# return ret
# else:
# return ''
# type_dict = {
# 'server': "server",
# 'bladecenter': u'刀箱',
# 'blade': u'刀片',
# 'vm': u'虚拟机',
# 'network': u'网络设备',
# 'storage': u'存储设备',
# 'tape': u'带库' ,
# 'security': u'安全设备',
# 'parts': u'配件' ,
# 'others': u'其它类',
# }
ret = eval("asset_obj.%s.%s" % (asset_type, attribute))
return ret
@require_role(role='user')
def asset_add(request):
"""
添加资产
"""
header_title, path1, path2 = u'添加', u'资产', u'添加'
emg = ''
smg = ''
asset_types = models.ASSET_TYPE_CHOICES #设备类型
asset_status = models.DEVICE_STATUS #设备状态
asset_contract = Contract.objects.all() #合同
cabinet_all = models.Cabinet.objects.all() #机柜
service_all = ServiceInfo.objects.all() #服务
os_all = models.OS.objects.all() #操作系统
current_user = User.objects.get(username=request.user.username) #当前登录用户
bladecenter_all = models.BladeCenter.objects.all()
# hosts_all = Asset.objects.select_related().all()
if request.method == 'GET':
asset_type = request.GET['asset_type']
modals_all = ProductModel.objects.filter(asset_type=asset_type)
include_html = 'iasset/asset/add/%s.html' % asset_type
if asset_type == 'vm':
hosts_all = Asset.objects.filter(model__asset_type="server")
elif asset_type == 'blade':
hosts_all = Asset.objects.filter(model__asset_type="bladecenter")
else:
hosts_all = Asset.objects.filter(Q(model__asset_type="server") | Q(model__asset_type="bladecenter"))
# print "asset_type:", asset_type
# print "modals_all:", modals_all
# print "service_all:", service_all
# print "cabinet_all:", cabinet_all
if request.method == 'POST':
# postdata = request.POST
postdata = copy.deepcopy(request.POST) #深复制才能修改postdata的值
print "POST:", postdata
print "type(request.POST):", type(postdata)
print "request.session:",request.session
# postdata['create_person'] = current_user.id
# postdata['update_person'] = current_user.id
asset_form = AssetForm(postdata)
# print 'asset_form:',asset_form
if asset_form.is_valid():
asset_name = asset_form.cleaned_data['name']
if models.Asset.objects.filter(name=asset_name):
emg = u'添加失败, 此设备 %s 已存在!' % asset_name
else:
asset_obj = asset_form.save(commit=False)
try:
# 由于asset和contract之间是多对多关系,默认不能为空,所以要单拿出来添加,
# 如果提交的数据中contract为空,那么不添加该字段到数据库。
# 在forms.py 验证时已将contract字段排除
contract_obj = Contract.objects.get(id=postdata['contract'])
except Exception,e:
print e
else:
asset_obj.contract.add(contract_obj)
asset_obj.create_person = current_user
asset_obj.update_person = current_user
asset_obj.save()
asset_type = postdata['assettype']
# init = {'asset': models.Asset.objects.get(name=asset_name)}
print "asset_obj:",asset_obj.id
# init = {'asset_id': asset_obj.id}
postdata['asset'] = asset_obj.id
# serverformset = ServerForm(postdata, initial=init)
# if serverformset.is_valid():
# serverformset.save()
# else:
# emg = serverformset.errors.as_json()
ret = device_save(asset_type,postdata)
if ret['status'] == 0:
smg = u'设备: %s添加成功' % asset_name
else:
emg = ret['emg']
else:
# emg = asset_form.non_field_errors()
emg = asset_form.errors.as_json()
print 'error message:',emg
return HttpResponse(json.dumps({"smg": smg, "emg": emg}))
return my_render('iasset/asset/add/index.html', locals(), request)
def device_save(asset_type, postdata):
"""
设备入库
:param asset_type:
:return:
"""
asset_type_dict = {
'server': ServerForm(postdata),
'bladecenter': BladeCenterForm(postdata),
'blade': BladeForm(postdata),
'vm': VmForm(postdata),
'network': NetworkForm(postdata),
'storage': StorageForm(postdata),
'tape': TapeForm(postdata),
'securit
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于python+Django的IT资产管理系统.zip (459个子文件)
select2-bootstrap.css 232KB
bootstrap.min.css 111KB
style.css 88KB
bootstrap.min.css 79KB
animate.css 64KB
select2-bootstrap.min.css 57KB
font-awesome.css 37KB
jquery-ui.css 36KB
jquery-ui.min.css 31KB
font-awesome.min.css 30KB
bootstrap-datepicker3.standalone.css 23KB
fullcalendar.css 23KB
bootstrap-datepicker3.css 22KB
bootstrap-datepicker3.standalone.min.css 21KB
bootstrap-datepicker3.min.css 21KB
jquery-ui.structure.css 18KB
jquery-ui.theme.css 18KB
select2.css 17KB
cikonss.css 17KB
jquery-ui.structure.min.css 15KB
select2.min.css 15KB
jquery-ui.theme.min.css 14KB
chosen.css 13KB
flatpickr.css 12KB
dropzone.css 11KB
airbnb.rtl.css 11KB
airbnb.css 11KB
layer.css 11KB
dark.rtl.css 11KB
dark.css 11KB
material_orange.rtl.css 11KB
material_orange.css 11KB
base16_flat.rtl.css 11KB
base16_flat.css 11KB
material_green.rtl.css 11KB
confetti.rtl.css 11KB
confetti.css 11KB
material_green.css 11KB
flatpickr.min.css 11KB
flatpickr.min.css 11KB
material_red.rtl.css 10KB
material_blue.rtl.css 10KB
material_blue.css 10KB
material_red.css 10KB
bootstrap-datetimepicker.css 9KB
magnific-popup.css 8KB
bootstrap-datetimepicker.min.css 8KB
bootstrap-table.css 7KB
jquery.steps.css 6KB
fullcalendar.print.css 5KB
basic.css 4KB
jquery.validator.css 3KB
colorbox.css 3KB
layer.ext.css 3KB
bootstrap-datetimepicker-standalone.css 2KB
custom.css 1KB
dragtable.css 985B
fontawesome-webfont.eot 162KB
glyphicons-halflings-regular.eot 20KB
loading.gif 15KB
loading.gif 6KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
loading.gif 457B
loading.gif 457B
.gitattributes 97B
.gitignore 267B
base.html 70KB
index-bak.html 69KB
index.html 22KB
list.html 19KB
edit.html 18KB
edit.html 18KB
add.html 16KB
add.html 16KB
index.html 16KB
edit.html 15KB
list-bak.html 14KB
add-flatpickr.html 14KB
add.html 13KB
edit.html 13KB
edit.html 13KB
add.html 12KB
edit.html 12KB
list.html 12KB
add.html 12KB
list.html 12KB
list.html 12KB
edit.html 12KB
add.html 12KB
list.html 11KB
list.html 11KB
list.html 11KB
list-bak.html 11KB
list.html 11KB
list.html 11KB
list.html 11KB
list.html 11KB
add.html 11KB
共 459 条
- 1
- 2
- 3
- 4
- 5
资源评论
学术菜鸟小晨
- 粉丝: 1w+
- 资源: 4940
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python 手写实现 iD3 决策树算法-根据信息增益公式.zip
- 411675952289057车联助手-小窗版(三星)3.5.1.apk
- 三种快速排序方法合并在一个文件中以便直接运行的Python代码示例
- 937712277954201实习5.word
- 2程序语言基础知识pdf1_1716337722703.jpeg
- 简单的Python示例,演示了如何使用TCP/IP协议进行基本的客户端和服务器通信
- 考试.sql
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功