{% extends 'base.html' %}
{% block title %}
Page {{ softwarelist.number }} of {{ softwarelist.paginator.num_pages }}.
{% if softwarelist.has_next %}
下一页
{% endif %}
{% block content %}
软件名字 | 授权数 | 版本号 | 操作 | |
---|---|---|---|---|
{{ mr.name }} | {{ mr.license_num }} | {{ mr.version }} | 编辑 删除 |
{% extends 'base.html' %}
{% block title %}
Page {{ manufactorylist.number }} of {{ manufactorylist.paginator.num_pages }}.
{% if manufactorylist.has_next %}
下一页
{% endif %}
{% block content %}
厂商名字 | 厂商电话 | 备注 | 操作 | |
---|---|---|---|---|
{{ mr.manufactory }} | {{ mr.support_num }} | {{ mr.memo }} | 编辑 删除 |
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
from xlwt import *
import StringIO
def search_software(request):
error = False
each_page = 5
mname=request.GET.get('mname','0')
if mname=='0' or mname.strip()=='':
record_list = Software.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_software.html',{'softwarelist':contacts,"mname":mname})
else:
record_list = Software.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_software.html',{'softwarelist':contacts,"mname":mname})
def add_software(request):
n = request.POST.get('softwarename')
v = request.POST.get('softwareversion')
l = request.POST.get('softwarelicense_num')
Software.objects.create(name=n,license_num=l,version=v)
return HttpResponseRedirect('search_software.html')
def edit_software(request):
id=request.GET.get('id')
iid=int(id)
name=request.GET.get('name')
l=request.GET.get('license_num')
v=request.GET.get('version')
Software.objects.filter(id=iid).update(name=name,license_num=l,version=v)
page=request.GET.get('page')
mname=request.GET.get('mname')
return HttpResponseRedirect('search_software.html?mname='+mname+"&&page="+page)
def del_software(request):
id=request.GET.get('id')
iid=int(id)
Software.objects.filter(id=iid).delete()
page=request.GET.get('page')
mname=request.GET.get('mname')
return HttpResponseRedirect('search_software.html?mname='+mname+"&&page="+page)
def batdel_software(request):
ids=request.GET.get('ids')
b=ids.split(',')
arr = map(int,b)
for aaa in arr:
Software.objects.filter(id=aaa).delete()
mname=request.GET.get('mname')
return HttpResponseRedirect('search_software.html?mname='+mname)
def excel_software(request):
mname=request.GET.get('mname','0')
if mname=='0' or mname.strip()=='':
list_obj = Software.objects.all()
mname=''
else:
list_obj = Software.objects.filter(name=mname)
if list_obj:
# 创建工作薄
ws = Workbook(encoding='utf-8')
w = ws.add_sheet(u"软件清单")
w.write(0, 0, "id")
w.write(0, 1, u"软件名字")
w.write(0, 2, u"授权数")
w.write(0, 3, u"版本号")
# 写入数据
excel_row = 1
for obj in list_obj:
data_id = obj.id
data_name = obj.name
data_license_num = obj.license_num
data_version = obj.version
w.write(excel_row, 0, data_id)
w.write(excel_row, 1, data_name)
w.write(excel_row, 2, data_license_num)
w.write(excel_row, 3, data_version)
excel_row += 1
sio = StringIO.StringIO()
ws.save(sio)
sio.seek(0)
response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=机房清单-'+mname+'.xls'
response.write(sio.getvalue())
return response
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
from xlwt import *
import StringIO
def search_manufactory(request):
error = False
each_page = 5
mname=request.GET.get('mname','0')
if mname=='0' or mname.strip()=='':
record_list = Manufactory.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_manufactory.html',{'manufactorylist':contacts,"mname":mname})
else:
record_list = Manufactory.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_manufactory.html',{'manufactorylist':contacts,"mname":mname})
def add_manufactory(request):
n = request.POST.get('manufactorymanufactory')
v = request.POST.get('manufactorysupport_num')
l = request.POST.get('manufactorymemo')
Manufactory.objects.create(manufactory=n,support_num=v,memo=l)
return HttpResponseRedirect('search_manufactory.html')
def edit_manufactory(request):
id=request.GET.get('id')
iid=int(id)
name=request.GET.get('manufactory')
l=request.GET.get('support_num')
v=request.GET.get('memo')
Manufactory.objects.filter(id=iid).update(manufactory=name,support_num=l,memo=v)
page=request.GET.get('page')
mname=request.GET.get('mname')
return HttpResponseRedirect('search_manufactory.html?mname='+mname+"&&page="+page)
def del_manufactory(request):
id=request.GET.get('id')
iid=int(id)
Manufactory.objects.filter(id=iid).delete()
page=request.GET.get('page')
mname=request.GET.get('mname')
return HttpResponseRedirect('search_manufactory.html?mname='+mname+"&&page="+page)
def batdel_manufactory(request):
ids=request.GET.get('ids')
b=ids.split(',')
arr = map(int,b)
for aaa in arr:
Manufactory.objects.filter(id=aaa).delete()
mname=request.GET.get('mname')
return HttpResponseRedirect('search_manufactory.html?mname='+mname)
def excel_manufactory(request):
mname=request.GET.get('mname','0')
if mname=='0' or mname.strip()=='':
list_obj = Manufactory.objects.all()
mname=''
else:
list_obj = Manufactory.objects.filter(name=mname)
if list_obj:
# 创建工作薄
ws = Workbook(encoding='utf-8')
w = ws.add_sheet(u"厂商清单")
w.write(0, 0, "id")
w.write(0, 1, u"厂商名字")
w.write(0, 2, u"电话")
w.write(0, 3, u"备注")
# 写入数据
excel_row = 1
for obj in list_obj:
data_id = obj.id
data_name = obj.manufactory
data_license_num = obj.support_num
data_version = obj.memo
w.write(excel_row, 0, data_id)
w.write(excel_row, 1, data_name)
w.write(excel_row, 2, data_license_num)
w.write(excel_row, 3, data_version)
excel_row += 1
sio = StringIO.StringIO()
ws.save(sio)
sio.seek(0)
response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=机房清单-'+mname+'.xls'
response.write(sio.getvalue())
return response
"""cmdb URL Configuration
The urlpatterns
list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from cmdbapp import machinaroomviews,serverviews,networkdeviceviews,securitydeviceviews,softwareviews,storagedeviceviews,manufactoryviews
from django.contrib.auth.views import *
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib import staticfiles
from django.views.static import serve
urlpatterns = [
url(r'^static/(?P
url(r'^base',machinaroomviews.base,name='base'),
url(r'^search_machinaroom.html',machinaroomviews.add_machinaroom,name='add_machinaroom'),
url(r'^edit_machinaroom.html',machinaroomviews.edit_machinaroom,name='edit_machinaroom'),
url(r'^del_machinaroom.html',machinaroomviews.del_machinaroom,name='del_machinaroom'),
url(r'^batdel_machinaroom.html',machinaroomviews.batdel_machinaroom,name='batdel_machinaroom'),
url(r'^excel_machinaroom.html',machinaroomviews.excel_machinaroom,name='excel_machinaroom'),
url(r'^login/',serverviews.search_server,name='search_server'),
url(r'^add_server.html',serverviews.edit_server,name="edit_server"),
url(r'^del_server.html',serverviews.del_server,name='del_server'),
url(r'^batdel_server.html',serverviews.batdel_server,name='batdel_server'),
url(r'^excel_server.html',serverviews.excel_server,name='excel_server'),
url(r'^search_networkdevice.html',networkdeviceviews.add_networkdevice,name="add_networkdevice"),
url(r'^edit_networkdevice.html',securitydeviceviews.search_securitydevice,name='search_securitydevice'),
url(r'^add_securitydevice.html',securitydeviceviews.edit_securitydevice,name="edit_securitydevice"),
url(r'^del_securitydevice.html',securitydeviceviews.del_securitydevice,name='del_securitydevice'),
url(r'^batdel_securitydevice.html',securitydeviceviews.batdel_securitydevice,name='batdel_securitydevice'),
url(r'^excel_securitydevice.html',securitydeviceviews.excel_securitydevice,name='excel_securitydevice'),
url(r'^search_storagedevice.html',storagedeviceviews.add_storagedevice,name="add_storagedevice"),
url(r'^edit_storagedevice.html',softwareviews.search_software,name='search_software'),
url(r'^add_software.html',manufactoryviews.search_manufactory,name='search_manufactory'),
url(r'^add_manufactory.html$',manufactoryviews.add_manufactory,name='add_manufactory'),
url(r'^edit_manufactory.html',manufactoryviews.edit_manufactory,name='edit_manufactory'),
url(r'^del_manufactory.html',manufactoryviews.del_manufactory,name='del_manufactory'),
url(r'^batdel_manufactory.html',manufactoryviews.batdel_manufactory,name='batdel_manufactory'),
url(r'^excel_manufactory.html',manufactoryviews.excel_manufactory,name='excel_manufactory'),
]