def get(self, request, server_id): server = Server.objects.get(id=server_id) scope = server.zctype user_name = server.owner.username if server.owner else '' # 该记录添加到历史表中 server_his = ServerHis(serverid=server.id, zctype=server.zctype.zctype, ipaddress=server.ipaddress, description=server.description, brand=server.brand, zcmodel=server.zcmodel, zcnumber=server.zcnumber, zcpz=server.zcpz, owner=user_name, undernet=server.undernet, guartime=server.guartime, comment='该记录被删除') server_his.save() # 删除该记录 server.delete() # 将操作记录添加到日志中 new_log = UserOperateLog(username=request.user.username, scope=scope, type='删除', content=str(server_id)) new_log.save() return HttpResponseRedirect((reverse('servers:server_list')))
def get(self, request, server_id): server = Server.objects.get(id=server_id) scope = server.zctype user_name = server.owner.username if server.owner else '' # 该记录添加到历史表中 server_his = ServerHis(serverid=server.id, zctype=server.zctype.zctype, An=server.An, Sn=server.Sn, ServerName=server.ServerName, SysName=server.SysName, Use=server.Use, Location=server.Location, Cabinet=server.Cabinet, BrandModels=server.BrandModels, PurchaseDate=server.PurchaseDate, Head=server.Head, Ipaddress=server.Ipaddress, WDate=server.WDate, Undernet=server.Undernet, Modify_time=server.Modify_time, Comment='该记录被删除') server_his.save() # 删除该记录 server.delete() # 将操作记录添加到日志中 new_log = UserOperateLog(username=request.user.username, scope=scope, type='删除', content=str(server_id)) new_log.save() return HttpResponseRedirect((reverse('servers:server_list')))
def post(self, request): server_id = int(request.POST.get('server_id')) server = Server.objects.filter(id=server_id).first() server_form = ServerForm(request.POST) # 判断表单是否正确 if server_form.is_valid(): server.zctype = ServerType.objects.filter( id=request.POST.get('zctype')).first() server.ipaddress = request.POST.get('ipaddress').strip().upper() server.description = request.POST.get( 'description').strip().upper() server.brand = request.POST.get('brand').strip().upper() server.zcmodel = request.POST.get('zcmodel') server.zcnumber = request.POST.get('zcnumber') server.zcpz = request.POST.get('zcpz').strip().upper() server.owner = UserProfile.objects.filter( id=request.POST.get('owner', 0)).first() server.undernet = request.POST.get('undernet') server.guartime = request.POST.get('guartime').strip().upper() server.comment = request.POST.get('comment').strip().upper() server.save() user_name = server.owner.username if server.owner else '' # 该记录添加到历史表中 server_his = ServerHis(serverid=server.id, zctype=server.zctype.zctype, ipaddress=server.ipaddress, description=server.description, brand=server.brand, zcmodel=server.zcmodel, zcnumber=server.zcnumber, zcpz=server.zcpz, owner=user_name, undernet=server.undernet, guartime=server.guartime, comment=server.comment) server_his.save() # 将操作记录添加到日志中 new_log = UserOperateLog(username=request.user.username, scope=server.zctype, type='修改', content=server_id) new_log.save() return HttpResponseRedirect((reverse('servers:server_list'))) else: users = UserProfile.objects.filter(is_superuser=0, is_staff='1') server_types = ServerType.objects.all() return render( request, 'servers/server_detail.html', { 'users': users, 'server': server, 'server_types': server_types, 'msg': '输入错误!', 'server_form': server_form })
def post(self, request): my_file = request.FILES.get('myfile', None) if not my_file: return render(request, 'files/file_upload.html', {'msg': '没有选择文件'}) year = str(datetime.datetime.now().year) month = str(datetime.datetime.now().month) day = str(datetime.datetime.now().day) username = request.user.username.upper() upload_path = os.path.join(root_path, username, year, month, day) if os.path.isfile(os.path.join(upload_path, my_file.name)): return render(request, 'files/file_upload.html', {'msg': my_file.name + '已存在'}) if not os.path.exists(upload_path): os.makedirs(upload_path) with open(os.path.join(upload_path, my_file.name), 'wb+') as f: for chunk in my_file.chunks(): f.write(chunk) # 将上传记录插入到文件表中 records = File() records.fileno = str(datetime.datetime.now().strftime( '%Y%m%d%H%M%S%f'))[:17] # 时间精确到0.001s,用作文件的编号 records.filename = my_file.name records.filepath = upload_path records.owner = username records.save() # 将上传记录插入到日志记录中 logs = UserOperateLog() logs.userno = request.user.userno logs.username = username logs.type = '上传' logs.fileno = records.fileno logs.filename = records.filename # 判断上传文件是否通过公用电脑上传 ip = get_client_ip(request) public_ip = PublicIp.objects.first() if public_ip: if ip in public_ip.host_ip: logs.comment = '拷入' else: logs.comment = '' logs.save() return HttpResponseRedirect((reverse('index')))
def get(self, request, file_id): file = File.objects.get(id=file_id) if (request.user.username.upper() != file.owner.upper() and request.user.role != '3' and request.user.is_superuser != 1): return HttpResponse(status=404) # 通过flag判断各种情况 flag = '' ip = get_client_ip(request) public_ip = PublicIp.objects.first() if public_ip: if ip in public_ip.host_ip: if file.first_check == '1' and file.second_check == '1' and file.isapprove == '1': flag = '公用可下载' else: flag = '公用不可下载' else: flag = '普通下载' if flag == '公用不可下载': return render(request, 'files/file_download_error.html', {'msg': '该公用电脑无法下载,请联系管理员~'}) else: filename = file.filename filepath = file.filepath if not os.path.isfile(os.path.join(filepath, filename)): return render(request, 'files/file_download_error.html', {'msg': '文件可能已经被删除,请联系管理员~'}) download_file = open(os.path.join(filepath, filename), 'rb') response = FileResponse(download_file) response['Content-Type'] = 'application/octet-stream' response[ 'Content-Disposition'] = 'attachment; filename=' + urlquote( filename) # 将下载记录插入到日志记录中 logs = UserOperateLog() logs.userno = request.user.userno logs.username = request.user.username.upper() logs.type = '下载' logs.filename = filename logs.fileno = file.fileno if flag == '公用可下载': logs.comment = '拷出' else: logs.comment = '' logs.save() return response
def post(self, request): zctype = ServerType.objects.filter( id=request.POST.get('zctype', 0)).first() ipaddress = request.POST.get('ipaddress').strip().upper() description = request.POST.get('description').strip().upper() brand = request.POST.get('brand').strip().upper() zcmodel = request.POST.get('zcmodel') zcnumber = request.POST.get('zcnumber') zcpz = request.POST.get('zcpz').strip().upper() owner = UserProfile.objects.filter( id=request.POST.get('owner', 0)).first() undernet = request.POST.get('undernet') guartime = request.POST.get('guartime').strip().upper() comment = request.POST.get('comment').strip().upper() server_form = ServerForm(request.POST) # 判断表单是否正确 if server_form.is_valid(): new_server = Server(zctype=zctype, ipaddress=ipaddress, description=description, brand=brand, zcmodel=zcmodel, zcnumber=zcnumber, zcpz=zcpz, owner=owner, undernet=undernet, guartime=guartime, comment=comment) new_server.save() user_name = owner.username if owner else '' # 该记录添加到历史表中 server_his = ServerHis(serverid=new_server.id, zctype=zctype.zctype, ipaddress=ipaddress, description=description, brand=brand, zcmodel=zcmodel, zcnumber=zcnumber, zcpz=zcpz, owner=user_name, undernet=undernet, guartime=guartime, comment=comment) server_his.save() # 将操作记录添加到日志中 new_log = UserOperateLog(username=request.user.username, scope=zctype.zctype, type='增加', content=server_his.serverid) new_log.save() return HttpResponseRedirect((reverse('servers:server_list'))) else: users = UserProfile.objects.filter(is_superuser=0) server_types = ServerType.objects.all() return render( request, 'servers/server_add.html', { 'msg': '输入错误!', 'users': users, 'server_form': server_form, 'server_types': server_types })
def post(self, request): zctype = ServerType.objects.filter( id=request.POST.get('zctype', 0)).first() An = request.POST.get('An').strip().upper() Sn = request.POST.get('Sn').strip().upper() ServerName = request.POST.get('ServerName').strip().upper() SysName = request.POST.get('SysName').strip().upper() Use = request.POST.get('Use').strip().upper() Location = request.POST.get('Location').strip().upper() Cabinet = request.POST.get('Cabinet').strip().upper() BrandModels = request.POST.get('BrandModels').strip().upper() PurchaseDate = request.POST.get('PurchaseDate').strip().upper() Head = request.POST.get('Head').strip().upper() Ipaddress = request.POST.get('Ipaddress').strip().upper() WDate = request.POST.get('WDate').strip().upper() Undernet = request.POST.get('Undernet').strip().upper() Comment = request.POST.get('Comment').strip().upper() #Modify_time = request.POST.get('Modify_time').strip().upper() server_form = ServerForm(request.POST) # 判断表单是否正确 if server_form.is_valid(): new_server = Server(zctype=zctype, An=An, Sn=Sn, ServerName=ServerName, SysName=SysName, Use=Use, Location=Location, Cabinet=Cabinet, BrandModels=BrandModels, PurchaseDate=PurchaseDate, Head=Head, Ipaddress=Ipaddress, WDate=WDate, Undernet=Undernet, Comment=Comment) new_server.save() #user_name = owner.username if owner else '' # 该记录添加到历史表中 server_his = ServerHis(serverid=new_server.id, zctype=zctype.zctype, An=An, Sn=Sn, ServerName=ServerName, SysName=SysName, Use=Use, Location=Location, Cabinet=Cabinet, BrandModels=BrandModels, PurchaseDate=PurchaseDate, Head=Head, Ipaddress=Ipaddress, WDate=WDate, Undernet=Undernet, Comment=Comment) server_his.save() # 将操作记录添加到日志中 new_log = UserOperateLog(username=request.user.username, scope=zctype.zctype, type='增加', content=server_his.serverid) new_log.save() return HttpResponseRedirect((reverse('servers:server_list'))) else: users = UserProfile.objects.filter(is_superuser=0) server_types = ServerType.objects.all() return render( request, 'servers/server_add.html', { 'msg': '输入错误!', 'users': users, 'server_form': server_form, 'server_types': server_types })
def post(self, request): server_id = int(request.POST.get('server_id')) server = Server.objects.filter(id=server_id).first() server_form = ServerForm(request.POST) # 判断表单是否正确 if server_form.is_valid(): server.zctype = ServerType.objects.filter( id=request.POST.get('zctype')).first() server.An = request.POST.get('An').strip().upper() server.Sn = request.POST.get('Sn').strip().upper() server.ServerName = request.POST.get('ServerName').strip().upper() server.SysName = request.POST.get('SysName').strip().upper() server.Use = request.POST.get('Use').strip().upper() server.Location = request.POST.get('Location').strip().upper() server.Cabinet = request.POST.get('Cabinet').strip().upper() #server.owner = UserProfile.objects.filter(id=request.POST.get('owner', 0)).first() server.BrandModels = request.POST.get('BrandModels') server.Head = request.POST.get('Head').strip().upper() server.Ipaddress = request.POST.get('Ipaddress').strip().upper() server.WDate = request.POST.get('WDate').strip().upper() server.Undernet = request.POST.get('Undernet').strip().upper() server.Comment = request.POST.get('Comment').strip().upper() server.save() user_name = server.owner.username if server.owner else '' # 该记录添加到历史表中 server_his = ServerHis(serverid=server.id, zctype=server.zctype.zctype, An=server.An, Sn=server.Sn, ServerName=server.ServerName, SysName=server.SysName, Use=server.Use, Location=server.Location, Cabinet=server.Cabinet, BrandModels=server.BrandModels, PurchaseDate=server.PurchaseDate, Head=server.Head, Ipaddress=server.Ipaddress, WDate=server.WDate, Undernet=server.Undernet, Comment=server.Comment) server_his.save() # 将操作记录添加到日志中 new_log = UserOperateLog(username=request.user.username, scope=server.zctype, type='修改', content=server_id) new_log.save() return HttpResponseRedirect((reverse('servers:server_list'))) else: users = UserProfile.objects.filter(is_superuser=0, is_staff='1') server_types = ServerType.objects.all() return render( request, 'servers/server_detail.html', { 'users': users, 'server': server, 'server_types': server_types, 'msg': '输入错误!', 'server_form': server_form })
def post(self, request): # if not GET, then proceed try: csv_file = request.FILES["csv_file"] if not csv_file.name.endswith('.csv'): return render(request, 'servers/server_upload.html', {'msg': 'File is not CSV type'}) if csv_file.multiple_chunks(): messages.error( request, "Uploaded file is too big (%.2f MB)." % (csv_file.size / (1000 * 1000), )) return HttpResponseRedirect( reverse("servers/server_upload.html")) file_data = csv_file.read().decode("utf-8") lines = file_data.split("\n") # loop over the lines and save them in db. If error , store as string and then display for line in lines: fields = line.split(",") data_dict = {} data_dict["zctype"] = fields[0] data_dict["An"] = fields[1] data_dict["Sn"] = fields[2] data_dict["ServerName"] = fields[3] data_dict["SysName"] = fields[4] data_dict["Use"] = fields[5] data_dict["Location"] = fields[6] data_dict["Cabinet"] = fields[7] data_dict["BrandModels"] = fields[8] data_dict["PurchaseDate"] = fields[9] data_dict["Head"] = fields[11] data_dict["Ipaddress"] = fields[12] data_dict["WDate"] = fields[13] data_dict["Undernet"] = fields[14] data_dict["Comment"] = fields[15] try: server_form = EventsForm(data_dict) if server_form.is_valid(): server_form.save() else: return render(request, 'servers/server_upload.html', {'msg': '导入失败!'}) except Exception as e: return render(request, 'servers/server_upload.html', {'msg': '导入失败!'}) pass except Exception as e: return render(request, 'servers/server_upload.html', {'msg': '输入错误!'}) ################################ # 判断表单是否正确 if server_form.is_valid(): new_server = Server(zctype=zctype, An=An, Sn=Sn, ServerName=ServerName, SysName=SysName, Use=Use, Location=Location, Cabinet=Cabinet, BrandModels=BrandModels, PurchaseDate=PurchaseDate, Head=Head, Ipaddress=Ipaddress, WDate=WDate, Undernet=Undernet, Comment=Comment) new_server.save() # user_name = owner.username if owner else '' # 该记录添加到历史表中 server_his = ServerHis(serverid=new_server.id, zctype=zctype.zctype, An=An, Sn=Sn, ServerName=ServerName, SysName=SysName, Use=Use, Location=Location, Cabinet=Cabinet, BrandModels=BrandModels, PurchaseDate=PurchaseDate, Head=Head, Ipaddress=Ipaddress, WDate=WDate, Undernet=Undernet, Comment=Comment) server_his.save() # 将操作记录添加到日志中 new_log = UserOperateLog(username=request.user.username, scope=zctype.zctype, type='增加', content=server_his.serverid) new_log.save() return HttpResponseRedirect((reverse('servers:server_list'))) else: users = UserProfile.objects.filter(is_superuser=0) server_types = ServerType.objects.all() return render( request, 'servers/server_upload.html', { 'msg': '输入错误!', 'users': users, 'server_form': server_form, 'server_types': server_types })