search_machinaroom.html
{% extends 'base.html' %}
{% block title %}
<script type="text/javascript" src="/static/scripts/jquery/jquery-1.7.1.js"></script>
<link href="/static/style/authority/basic_layout.css" rel="stylesheet" type="text/css">
<link href="/static/style/authority/common_style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/scripts/authority/commonAll.js"></script>
<script type="text/javascript" src="/static/scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="/static/scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="/static/style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
<script type="text/javascript" src="/static/scripts/artDialog/artDialog.js?skin=default"></script>
<div id="container">
<div class="ui_content">
<div class="ui_text_indent">
<div id="box_border">
<div id="box_top">搜索</div>
机房名字 <input type="text" id="mname" name="mname" value="{{ mname }}" class="ui_input_txt02" />
</div>
<div id="box_top">新增/编辑</div>
<form id="submitForm" name="submitForm" method="post" action="add_machinaroom.html">
<input type="hidden" id="machinaroomid" name="machinaroomid"/>
机房名字 <input type="text" id="machinaroomname" name="machinaroomname" class="ui_input_txt02" />
机房位置 <input type="text" id="machinaroomlocation" name="machinaroomlocation" class="ui_input_txt02" />
机房VPN <input type="text" id="machinaroomvpnurl" name="machinaroomvpnurl" class="ui_input_txt02" />
备注 <input type="text" id="machinaroommemo" name="machinaroommemo" class="ui_input_txt02" />
</div>
<div id="box_bottom">
<div class="pagination">
<span class="current">
{% if machinaroomlist.has_previous %}
<a href="javascript:void(0)" onclick="search_machina({{ machinaroomlist.previous_page_number }});">上一页</a>
{% endif %}
<span class="current">
Page {{ machinaroomlist.number }} of {{ machinaroomlist.paginator.num_pages }}.
</span>
{% if machinaroomlist.has_next %}
<a href="javascript:void(0)" onclick="search_machina({{ machinaroomlist.next_page_number }});">下一页</a>
{% endif %}
</span>
</div>
<input type="button" value="查询" class="ui_input_btn01" onclick="search_machina(1);"/>
<input type="submit" value="新增" class="ui_input_btn01" />
<input type="button" value="编辑" class="ui_input_btn01" onclick="edit_machinaroom({{ machinaroomlist.number }});" />
<input type="button" value="删除" class="ui_input_btn01" onclick="batdel_machinaroom();" />
<input type="button" value="导入" class="ui_input_btn01" id="importBtn" />
<input type="button" value="导出" class="ui_input_btn01" onclick="exportExcel();" />
</div>
</form>
</div>
</div>
{% endblock %}
{% block content %}
<div class="ui_content">
<div class="ui_tb">
<table class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tr>
<th width="30"><input type="checkbox" id="id" name="id" />
</th>
<th>机房名字</th>
<th>机房位置</th>
<th>VPN链接</th>
<th>备注</th>
<th>操作</th>
</tr>
{% for mr in machinaroomlist.object_list %}
<tr>
<td><input type="checkbox" name="idcheck" value={{ mr.id }} class="acb" /></td>
<td>{{ mr.name }}</td>
<td>{{ mr.location }}</td>
<td>{{ mr.vpnurl }}</td>
<td>{{ mr.memo }}</td>
<td>
<a href="javascript:void(0)" onclick="edit_mr('{{ mr.id }}','{{ mr.name }}','{{ mr.location }}','{{ mr.vpnurl }}','{{ mr.memo }}')" class="edit">编辑</a>
<a href="javascript:void(0)" onclick="del_machinaroom({{ mr.id }},{{ machinaroomlist.number }});">删除</a>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
<script type="text/javascript">
function search_machina(page){
var text1 = document.getElementById("mname").value;
var myurl="search_machinaroom.html"+"?"+"mname="+text1+"&&page="+page;
window.location.assign(encodeURI(myurl))
}
function edit_mr(id,name,ll,vpnurl,memo){
document.getElementById("machinaroomid").value=id;
document.getElementById("machinaroomname").value=name;
document.getElementById("machinaroomlocation").value=ll;
document.getElementById("machinaroomvpnurl").value=vpnurl;
document.getElementById("machinaroommemo").value=memo;
}
function edit_machinaroom(page){
var text1 = document.getElementById("mname").value;
id=document.getElementById("machinaroomid").value;
name=document.getElementById("machinaroomname").value;
ll=document.getElementById("machinaroomlocation").value;
vpnurl=document.getElementById("machinaroomvpnurl").value;
memo=document.getElementById("machinaroommemo").value;
var myurl="edit_machinaroom.html"+"?"+"id="+id+"&&name="+name+"&&location="+ll+"&&vpnurl="+vpnurl+"&&memo="+memo+"&&mname="+text1+"&&page="+page;
window.location.assign(encodeURI(myurl))
}
function del_machinaroom(id,page){
if(window.confirm('确定要删除该记录吗?')){
var text1= document.getElementById("mname").value;
var myurl="del_machinaroom.html"+"?"+"id="+id+"&&mname="+text1+"&&page="+page;
window.location.assign(encodeURI(myurl))
return true;
}else{
//alert("取消");
return false;
}
}
function batdel_machinaroom(){
if(window.confirm('确定要删除记录吗?')){
obj = document.getElementsByName("idcheck");
var text1= document.getElementById("mname").value;
check_val = [];
for(k in obj){
if(obj[k].checked)
check_val.push(obj[k].value);
}
var myurl="batdel_machinaroom.html"+"?"+"ids="+check_val+"&&mname="+text1;
window.location.assign(encodeURI(myurl))
return true;
}else{
return false;
}
}
</script>
{% endblock %}
views.py
-- coding: utf-8 --
from future import unicode_literals
from django.shortcuts import render,render_to_response
from django.core.paginator import Paginator,InvalidPage,EmptyPage
from cmdbapp.models import *
from django.http import HttpResponse
from django.http import HttpResponseRedirect
Create your views here.
def main_page(request):
return render_to_response('main_page.html', {'user':request.user })
def base(request):
return render_to_response('base.html')
def search_machinaroom(request):
error = False
each_page = 5
mname=request.GET.get('mname','0')
if mname=='0' or mname.strip()=='':
record_list = Machinaroom.objects.all()
mname=''
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_machinaroom.html',{'machinaroomlist':contacts,"mname":mname})
else:
record_list = Machinaroom.objects.filter(name=mname)
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_machinaroom.html',{'machinaroomlist':contacts,"mname":mname})
def add_machinaroom(request):
n = request.POST.get('machinaroomname')
l = request.POST.get('machinaroomlocation')
v = request.POST.get('machinaroomvpnurl')
m = request.POST.get('machinaroommemo')
Machinaroom.objects.create(name=n,location=l,vpnurl=v,memo=m)
return HttpResponseRedirect('search_machinaroom.html')
def edit_machinaroom(request):
id=request.GET.get('id')
iid=int(id)
name=request.GET.get('name')
location=request.GET.get('location')
vpnurl=request.GET.get('vpnurl')
memo=request.GET.get('memo')
Machinaroom.objects.filter(id=iid).update(name=name,location=location,vpnurl=vpnurl,memo=memo)
page=request.GET.get('page')
mname=request.GET.get('mname')
return HttpResponseRedirect('search_machinaroom.html?mname='+mname+"&&page="+page)
def del_machinaroom(request):
id=request.GET.get('id')
iid=int(id)
Machinaroom.objects.filter(id=iid).delete()
page=request.GET.get('page')
mname=request.GET.get('mname')
return HttpResponseRedirect('search_machinaroom.html?mname='+mname+"&&page="+page)
def batdel_machinaroom(request):
ids=request.GET.get('ids')
b=ids.split(',')
arr = map(int,b)
for aaa in arr:
Machinaroom.objects.filter(id=aaa).delete()
mname=request.GET.get('mname')
return HttpResponseRedirect('search_machinaroom.html?mname='+mname)
models.py
-- coding: utf-8 --
from future import unicode_literals
from django.db import models
class Machinaroom(models.Model):
id=models.AutoField(primary_key=True)
name=models.CharField(max_length=200,default=u'机房')
location=models.CharField(max_length=200,default=u'厦门')
vpnurl=models.URLField(default="")
memo = models.CharField(u'备注', max_length=200,default="")
def unicode(self):
return self.name
class Server(models.Model):
"""
服务器信息
"""
machinaroom= models.ForeignKey(Machinaroom)
hostname = models.CharField(max_length=128, unique=True)
sn = models.CharField('SN号', max_length=64,default="")
manufacturer = models.CharField(verbose_name='制造商', max_length=64, default="")
model = models.CharField('型号', max_length=64, default="")
manage_ip = models.GenericIPAddressField('管理IP', default="")
other_ip = models.GenericIPAddressField('其他IP', default="")
os_platform = models.CharField('系统', max_length=16, default="")
os_version = models.CharField('系统版本', max_length=16, default="")
cpu_count = models.IntegerField('CPU个数', default=0)
cpu_physical_count = models.IntegerField('CPU物理个数', default=0)
cpu_model = models.CharField('CPU型号', max_length=128, default="")
memory_model=models.CharField('memory型号', max_length=128, default="")
memory_size=models.CharField('memory大小',max_length=128, default="")
disk_memo=models.CharField('硬盘信息',max_length=200, default="")
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
class Meta:
verbose_name_plural = "服务器表"
def __str__(self):
return self.hostname
class VirtualMachina(models.Model):
"""虚拟机信息"""
server= models.ForeignKey(Server)
hostname = models.CharField(max_length=128, unique=True)
manage_ip = models.GenericIPAddressField('管理IP', default="")
other_ip = models.GenericIPAddressField('其他IP', default="")
os_platform = models.CharField('系统', max_length=16, default="")
os_version = models.CharField('系统版本', max_length=16, default="")
cpu_memo = models.CharField('CPU信息',max_length=128, default="")
memory_size=models.CharField('memory大小',max_length=128, default="")
disk_memo=models.CharField('硬盘信息',max_length=200, default="")
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
def __str__(self):
return self.hostname
class NetworkDevice(models.Model):
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
machinaroom= models.ForeignKey(Machinaroom)
hostname = models.CharField(max_length=128, unique=True)
port_num = models.SmallIntegerField(u'端口个数', default=0)
device_detail = models.TextField(u'设置详细配置', default="")
model = models.CharField(u'型号', max_length=128, default="")
manage_ip = models.GenericIPAddressField('管理IP', default="")
other_ip = models.GenericIPAddressField('其他IP', default="")
class Meta:
verbose_name = '网络设备'
verbose_name_plural = "网络设备"
def __str__(self):
return self.hostname
class SecurityDevice(models.Model):
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
machinaroom= models.ForeignKey(Machinaroom)
type=models.CharField(u'类型', max_length=128, default="")
hostname = models.CharField(max_length=128, unique=True)
port_num = models.SmallIntegerField(u'端口个数', default=0)
device_detail = models.TextField(u'设置详细配置', default="")
model = models.CharField(u'型号', max_length=128, default="")
manage_ip = models.GenericIPAddressField('管理IP', default="")
other_ip = models.GenericIPAddressField('其他IP', default="")
class Meta:
verbose_name = '安全设备'
verbose_name_plural = "安全设备"
def __str__(self):
return self.hostname
class StorageDevice(models.Model):
"""存储设备"""
machinaroom= models.ForeignKey(Machinaroom)
model = models.CharField(u'型号', max_length=128, default="")
id =models.AutoField(primary_key=True)
manage_ip = models.GenericIPAddressField('管理IP', default="")
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
disk_memo=models.CharField('容量信息',max_length=200, default="")
memo = models.TextField(u'备注', default="")
class Meta:
verbose_name = '存储设备'
verbose_name_plural = "存储设备"
def __str__(self):
return self.model
class Software(models.Model):
sub_assset_type_choices = (
(0, 'OS'),
(1, '办公\开发软件'),
(2, '业务软件'),
)
sub_asset_type = models.SmallIntegerField(choices=sub_assset_type_choices, verbose_name="服务器类型", default=0)
license_num = models.IntegerField(verbose_name="授权数",default=0)
version = models.CharField(u'软件/系统版本', max_length=64, help_text=u'eg. CentOS release 6.5 (Final)', unique=True)
id =models.AutoField(primary_key=True)
def __str__(self):
return self.version
class Meta:
verbose_name = '软件/系统'
verbose_name_plural = "软件/系统"
class Manufactory(models.Model):
"""厂商"""
id =models.AutoField(primary_key=True)
manufactory = models.CharField(u'厂商名称', max_length=64, unique=True)
support_num = models.CharField(u'支持电话', max_length=30, default="")
memo = models.CharField(u'备注', max_length=128, default="")
def __str__(self):
return self.manufactory
class Meta:
verbose_name = '厂商'
verbose_name_plural = "厂商"
urls.py
urlpatterns = [
url(r'^static/(?P<path>.*)',views.main_page,name='main_page'),
url(r'^base',views.base,name='base'),
url(r'^search_machinaroom.html',views.add_machinaroom,name='add_machinaroom'),
url(r'^edit_machinaroom.html',views.edit_machinaroom,name='edit_machinaroom'),
url(r'^del_machinaroom.html',views.del_machinaroom,name='del_machinaroom'),
url(r'^batdel_machinaroom.html',views.batdel_machinaroom,name='batdel_machinaroom'),
url(r'^login/$', login),
]