def SimInfoMgr_Del(request): user = request.user try: id_i = int(request.GET['id']) except: return HttpResponseRedirect('/msg?t=请求参数有误') else: if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_AddNewSim'): try: p1 = SimInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=指定的sim卡不存在') else: return HttpResponseRedirect('/msg?t=无操作权限') try: #保存日志记录 SaveLog(user, 3003, p1, 3) p1.delete() except: return HttpResponseRedirect('/msg?t=删除失败') else: return HttpResponseRedirect('/SimInfo') return render_to_response('SimInfo.html',{'form':form,'SimInfoResult':SimInfoResult,'MainMenu':MainMenu},\ context_instance = RequestContext(request))
def SimInfoMgr_Assign(request): user = request.user if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_AssignSim'): result = '' if request.method == 'POST': form = SimInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd #print SimInfo.objects.get(id = 2) #这里添加数据 #CurrState = 1 #获取要修改的数据值 p1 = SimInfo.objects.get(id=request.POST['p_id']) p1.CurrOwner = User.objects.get(id=int(cd['CurrOwner'])) #p1.CurrState = CurrState p1.BorrowMan = None p1.BorrowDate = None p1.UpdateDate = int(time.time()) try: p1.save() except: result = '分配SIM失败!' else: result = '分配成功' #p2 = SimHisState(SimInfo=p1,\ # CurrState=CurrState,\ # CreateDate=int(time.time())) #p2.save() #保存日志记录 SaveLog(user, 3004, p1, 3) return HttpResponseRedirect('/msg?t=' + result) else: id_i = int(request.GET['id']) #获取要修改的数据值 try: p1 = SimInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=指定的SIM未找到!') if p1.CurrState != 11: return HttpResponseRedirect('/msg?t=不是可借状态的SIM不能分配!') #IfSimI = 0 #if p1.IfSim: # IfSimI = 1 #对待修改的数据进行初始化 form = SimInfoQue( initial = {'PhoneNum':p1.PhoneNum,\ 'CurrOwner':p1.CurrOwner } ) return render_to_response('SimInfo_Assign.html',{'form':form, 'result':result,\ 'p_id':id_i},\ context_instance = RequestContext(request)) else: return HttpResponseRedirect('/msg?t=无权进行分配SIM操作!')
def DeviceMaintainMgr_Del(request): global tag user = request.user try: id_i = int(request.GET['id']) except: #未进行操作字段提交 return HttpResponseRedirect('/msg?t=指定参数出错') else: try: p1 = PhoneInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=指定的手机不存在!') if p1.CurrState == 12: return HttpResponseRedirect('/msg?t=已借出的设备不能删除') if user.username == 'admin' or user.has_perm('PhoneMgr.DeviceMaintain_AddNewDevice'): try: #保存日志记录 SaveLog(user,1003,p1,1) p1.delete() except: return HttpResponseRedirect('/msg?t=删除失败') else: return HttpResponseRedirect('/DeviceMaintain') else: return HttpResponseRedirect('/msg?t=无权操作!') return render_to_response('Device.html',{'PhoneInfoResult':PhoneInfoResult,'MainMenu':MainMenu},\ context_instance = RequestContext(request))
def SimInfoMgr_Add(request): user = request.user if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_AddNewSim'): SimInfo_add_result = '' if request.method == 'POST': form = SimInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd #print SimInfo.objects.get(id = 2) #这里添加数据 #print cd['ProvinceInfo'],cd['CarrierInfo'] CurrState = 11 if int(cd['CurrOwner']) == 0: CurrOwner = None else: CurrOwner = User.objects.get(id=int(cd['CurrOwner'])) p1 = SimInfo(PhoneNum=cd['PhoneNum'],\ Province=Province.objects.get(id = int(cd['ProvinceInfo'])),\ Carrier=Carrier.objects.get(id = int(cd['CarrierInfo'])),\ IMSI=cd['IMSI'],\ CurrOwner = CurrOwner,\ CurrState = CurrState,\ ServerPass = cd['ServerPass'],\ SimWhiteList = SimWhiteList.objects.get(id = int(cd['SimWhiteList'])),\ SimAbout = cd['SimAbout'] ) try: p1.save() except: SimInfo_add_result = '添加数据失败!' traceback.print_exc() else: SimInfo_add_result = '添加成功' #添加成功后在手机状态表中添加一条记录 #if p1.CurrOwner is None: #没有归属人 # p2 = SimCurrState(SimInfo=p1,CurrState=0) #else: # p2 = SimCurrState(SimInfo=p1,CurrState=1) p2 = SimHisState(SimInfo=p1, CurrState=CurrState) p2.save() #保存日志记录 SaveLog(user, 3001, p1, 3) #print SimInfo_add_result.decode('utf8').encode('gbk') return HttpResponseRedirect('/msg?t=' + SimInfo_add_result) else: form = SimInfoQue() return render_to_response('SimInfo_add.html',{'form':form,'SimInfo_add_result':SimInfo_add_result},\ context_instance = RequestContext(request)) else: return HttpResponseRedirect('/msg?t=无操作权限')
def UserInfoMgr_Add(request): global tag user = request.user if user.username == 'admin' or user.has_perm( 'PhoneMgr.UserMgr_CanReg') or user in [ p.Owner for p in PhoneInfo.objects.all() ]: UserInfo_add_result = '' if request.method == 'POST': form = UserInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd #print SimInfo.objects.get(id = 2) #生成一个用户 try: user1 = User.objects.create_user(username=cd['username'],\ email=cd['email'],\ password=cd['passwd']) user1.save() except: UserInfo_add_result = '添加用户失败!' return HttpResponseRedirect('/msg?t=' + UserInfo_add_result) #添加组 group = Group.objects.get(id=int(cd['Group'])) user1.groups.add(group) #添加到用户组中 p1 = UserInfo(Userid=user1,\ EngName = cd ['EngName'],\ ChnName = cd['ChnName'],\ Dept = cd['Dept'],\ UserInfoAbout = cd['UserInfoAbout'],\ IsCheck = 1) try: p1.save() except Exception, e: UserInfo_add_result = '添加用户失败!' #print e #traceback.print_exc() else: UserInfo_add_result = '添加用户成功' #保存日志 SaveLog(user, 2001, user1, 2) return HttpResponseRedirect('/msg?t=' + UserInfo_add_result) else: form = UserInfoQue( initial = { 'Group':2,\ }, ) return render_to_response('UserInfo_add.html',{'form':form,'PhoneInfo_add_result':UserInfo_add_result},\ context_instance = RequestContext(request))
def SimInfoMgr_UnAssign(request): user = request.user if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_CancelAssignSim'): op_result = '' id_i = int(request.GET['id']) #获取要修改的数据值 try: p1 = SimInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=指定的SIM不存在!') if p1.CurrState == 12: return HttpResponseRedirect('/msg?t=先将SIM归还再取消分配') #if user.username == 'admin' or (p1.CurrOwner is not None and p1.CurrOwner == user): # pass #else: # op_result = '不是SIM归属者不能上交' # return HttpResponseRedirect('/msg?t='+op_result) p1.CurrOwner = None p1.CurrState = 11 # 变成可借状态 p1.BorrowMan = None p1.BorrowDate = None p1.BorrowAuthMan = None p1.BackMan = None p1.BackDate = None p1.BackAuthMan = None p1.UpdateDate = int(time.time()) try: p1.save() except: op_result = '取消分配失败' return HttpResponseRedirect('/msg?t=' + op_result) else: op_result = '取消分配成功' p2 = SimHisState(SimInfo=p1,\ CurrState=p1.CurrState,\ CreateDate=int(time.time())) p2.save() #保存日志记录 SaveLog(user, 3005, p1, 3) return HttpResponseRedirect('/SimInfo') else: return HttpResponseRedirect('/msg?t=无权进行取消分配操作!')
def SimInfoMgr_Back(request): user = request.user if True: op_result = '' id_i = int(request.GET['id']) #获取要修改的数据值 try: p1 = SimInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=对应的SIM未找到!') if p1.CurrState == 11: return HttpResponseRedirect('/msg?t=已归还SIM不能重复归还') if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_ReturnSim') or p1.CurrOwner == user: pass else: op_result = '无归还SIM权限' return HttpResponseRedirect('/msg?t=' + op_result) p1.CurrState = 11 # 变成可借 p1.BorrowMan = None p1.UpdateDate = int(time.time()) try: p1.save() except: op_result = '确定归还失败' return HttpResponseRedirect('/msg?t=' + op_result) else: op_result = '归还成功' p2 = SimHisState(SimInfo=p1,\ CurrState=p1.CurrState,\ CreateDate=int(time.time())) p2.save() #保存日志记录 SaveLog(user, 3007, p1, 3) return HttpResponseRedirect('/SimInfo')
def UserInfoMgr_Del(request): global tag user = request.user if user.username == 'admin' or user.has_perm( 'PhoneMgr.UserMgr_DelUserInfo'): try: id_i = int(request.GET['id']) except: result = UserInfo.objects.all() try: page = int(request.GET['page']) except: tag = result else: if page > 0 and tag is not None: result = tag else: try: p1 = UserInfo.objects.get(id=id_i) p2 = p1.Userid except: return HttpResponseRedirect('/msg?t=无效的用户') #判断是否本人 if p2 == user: return HttpResponseRedirect('/msg?t=不能删除本人') try: #保存日志 SaveLog(user, 2003, p2, 2) p1.delete() p2.delete() except: return HttpResponseRedirect('/msg?t=删除用户失败') else: return HttpResponseRedirect('/UserMgr') return render_to_response('UserInfo.html',{'UserInfoResult':result,'MainMenu':MainMenu},\ context_instance = RequestContext(request)) else: return HttpResponseRedirect('/msg?t=无权操作!')
def SimInfoMgr_Borrow(request): user = request.user if True: op_result = '' if request.method == 'POST': form = SimInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd #print SimInfo.objects.get(id = 2) #这里添加数据 CurrState = 12 #分配SIM借出 #获取要修改的数据值 p1 = SimInfo.objects.get(id=request.POST['p_id']) #进行状态检查 if p1.CurrState == 12: return HttpResponseRedirect('/msg?t=指定的SIM已经借出!') p1.BorrowMan = User.objects.get(id=int(cd['BorrowMan'])) p1.BorrowDate = int(time.time()) p1.IfBorrowAuth = 1 p1.BorrowAuthMan = user p1.CurrState = CurrState p1.UpdateDate = int(time.time()) #进行操作合法性检查 if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_BorrowSim' ) or p1.CurrOwner == user: pass else: return HttpResponseRedirect('/msg?t=无权进行借出操作!') try: p1.save() except: op_result = 'SIM借出失败!' else: op_result = 'SIM借出成功' p2 = SimHisState(SimInfo=p1,\ BorrowMan = p1.BorrowMan,\ BorrowDate = p1.BorrowDate,\ CurrState=CurrState,\ BorrowAuthMan = p1.BorrowAuthMan,\ CreateDate=int(time.time())) p2.save() #保存日志记录 SaveLog(user, 3006, p1, 3) return HttpResponseRedirect('/msg?t=' + op_result) else: id_i = int(request.GET['id']) #获取要修改的数据值 try: p1 = SimInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=错误的操作!') if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_BorrowSim') or p1.CurrOwner == user: pass else: return HttpResponseRedirect('/msg?t=无权进行借出操作!') if p1.CurrState == 12: return HttpResponseRedirect('/msg?t=已借出的SIM不能重复借出') #对待修改的数据进行初始化 form = SimInfoQue( initial = {'PhoneNum':p1.PhoneNum,\ 'BorrowMan':p1.BorrowMan } ) return render_to_response('SimInfo_Borrow.html',{'form':form, 'op_result':op_result,\ 'p_id':id_i},\ context_instance = RequestContext(request))
def SimInfoMgr_Mod(request): user = request.user if user.username == 'admin' or user.has_perm( 'PhoneMgr.SimMaintain_UpdateSimInfo'): SimInfo_mod_result = '' if request.method == 'POST': #print request form = SimInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd CurrState = 0 if int(cd['CurrOwner']) == 0: CurrOwner = None else: CurrOwner = User.objects.get(id=int(cd['CurrOwner'])) CurrState = 1 p1 = SimInfo.objects.get(id=request.POST['p_id']) p1.PhoneNum = cd['PhoneNum'] p1.Province = Province.objects.get(id=int(cd['ProvinceInfo'])) p1.Carrier = Carrier.objects.get(id=int(cd['CarrierInfo'])) p1.IMSI = cd['IMSI'] p1.CurrOwner = CurrOwner p1.ServerPass = cd['ServerPass'] p1.SimWhiteList = SimWhiteList.objects.get( id=int(cd['SimWhiteList'])) p1.SimAbout = cd['SimAbout'] try: p1.save() except: SimInfo_mod_result = '修改数据失败' else: SimInfo_mod_result = '修改数据成功' #修改sim状态表的内容 #p2 = p1.simcurrstate_set.all()[0] #if CurrOwner is None: # #print p2 # p2.CurrState = 0 #else: # p2.CurrState = 1 p2 = SimHisState(SimInfo=p1, CurrState=CurrState) p2.save() #保存日志记录 SaveLog(user, 3002, p1, 3) return HttpResponseRedirect('/msg?t=' + SimInfo_mod_result) else: id_i = int(request.GET['id']) #获取要修改的数据值 try: p1 = SimInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=错误的操作!') #对待修改的数据进行初始化 form = SimInfoQue( initial = {'PhoneNum':p1.PhoneNum,\ 'ProvinceInfo':p1.Province.id,\ 'CarrierInfo':p1.Carrier.id,\ 'IMSI':p1.IMSI,\ 'CurrOwner':p1.CurrOwner,\ 'ServerPass':p1.ServerPass,\ 'SimWhiteList':p1.SimWhiteList.id,\ 'SimAbout':p1.SimAbout }, ) return render_to_response('SimInfo_mod.html',{'form':form,\ 'SimInfo_mod_result':SimInfo_mod_result,\ 'p_id':id_i},\ context_instance = RequestContext(request)) else: return HttpResponseRedirect('/msg?t=无操作权限')
def UserInfoMgr_Mod(request): user = request.user if user.username == 'admin' or user.has_perm( 'PhoneMgr.UserMgr_UpdateUserInfo'): UserInfo_mod_result = '' if request.method == 'POST': #print request form = UserInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd p1 = UserInfo.objects.get(id=request.POST['p_id']) p2 = p1.Userid p1.EngName = cd['EngName'] p1.ChnName = cd['ChnName'] p1.Dept = cd['Dept'] p1.UserInfoAbout = cd['UserInfoAbout'] #修改系统表信息 p2.username = cd['username'] if len(cd['passwd']) == 0: pass else: p2.set_password(cd['passwd']) p2.email = cd['email'] p2.username = cd['username'] #添加组 group = Group.objects.get(id=int(cd['Group'])) p2.groups.clear() p2.groups.add(group) try: p1.save() p2.save() except: UserInfo_mod_result = '修改数据失败' else: UserInfo_mod_result = '修改数据成功' #保存日志 SaveLog(user, 2002, p2, 2) return HttpResponseRedirect('/msg?t=' + UserInfo_mod_result) else: id_i = int(request.GET['id']) #获取要修改的数据值 try: p1 = UserInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=错误的操作!') p2 = p1.Userid #对待修改的数据进行初始化 #print 'aaa:',len(p2.groups.all()) if len(p2.groups.all()) == 0: groupid = 1 else: groupid = p2.groups.all()[0].id form = UserInfoQue( initial = {'username':p2.username,\ 'EngName':p1.EngName,\ 'ChnName':p1.ChnName,\ 'Dept':p1.Dept,\ 'passwd':'',\ 'email':p2.email,\ 'Group':groupid,\ 'UserInfoAbout':p1.UserInfoAbout }, ) return render_to_response('UserInfo_mod.html',{'form':form,\ 'User_mod_result':UserInfo_mod_result,\ 'p_id':id_i},\ context_instance = RequestContext(request)) else: return HttpResponseRedirect('/msg?t=无权操作!')
def DeviceMaintainMgr_Mod(request): user = request.user if user.username == 'admin' or user.has_perm('PhoneMgr.DeviceMaintain_UpdateDeviceState'): PhoneInfo_mod_result = '' if request.method == 'POST': #print request form = PhoneInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd #if int(cd['Owner']) == 0: # owner = None #else: # owner = User.objects.get(id = int(cd['Owner'])) p1 = PhoneInfo.objects.get(id = request.POST['p_id']) p1.PhoneName = cd['PhoneName'] p1.ProductInfo = ProductInfo.objects.get(id = int(cd['ProductInfo'])) #p1.ModelInfo = ModelInfo.objects.get(id = int(cd['ModelInfo'])) p1.OsInfo = OsInfo.objects.get(id = int(cd['OsInfo'])) p1.OsVersionInfo = OsVersionInfo.objects.get(id = int(cd['OsVersionInfo'])) p1.CpuType = cd['CpuType'] p1.CpuCoreNum = int(cd['CpuCoreNum']) p1.ResolutionInfo = ResolutionInfo.objects.get(id = int(cd['ResolutionInfo'])) p1.ScreenSizeInfo = ScreenSizeInfo.objects.get(id = int(cd['ScreenSizeInfo'])) p1.MemoryInfo = MemoryInfo.objects.get(id = int(cd['MemoryInfo'])) p1.IMEI = cd['IMEI'] p1.IfTel = int(cd['IfTel']) #p1.IfSim = int(cd['IfSim']) #p1.SimInfo = SimInfo.objects.get(id = int(cd['SimInfo'])) #p1.Owner = owner p1.FundId = cd['FundId'] p1.HealthState = int(cd['HealthState']) p1.About = cd['About'] p1.UpdateDate = int(time.time()) try: p1.save() except: PhoneInfo_mod_result = '修改数据失败' else: PhoneInfo_mod_result = '修改数据成功' #保存日志记录 SaveLog(user,1002,p1,1) return HttpResponseRedirect('/msg?t='+PhoneInfo_mod_result) else: id_i = int(request.GET['id']) #获取要修改的数据值 try: p1 = PhoneInfo.objects.get(id=id_i) except: return HttpResponseRedirect('/msg?t=错误的操作!') #IfSimI = 0 #if p1.IfSim: # IfSimI = 1 #对待修改的数据进行初始化 form = PhoneInfoQue( initial = {'PhoneName':p1.PhoneName,\ 'ProductInfo':p1.ProductInfo.id,\ #'ModelInfo':p1.ModelInfo.id,\ 'OsInfo':p1.OsInfo.id,\ 'OsVersionInfo':p1.OsVersionInfo.id,\ 'ResolutionInfo':p1.ResolutionInfo.id,\ 'ScreenSizeInfo':p1.ScreenSizeInfo.id,\ 'CpuType':p1.CpuType,\ 'CpuCoreNum':p1.CpuCoreNum,\ 'IMEI':p1.IMEI,\ 'FundId':p1.FundId,\ 'IfTel':p1.IfTel,\ #'IfSim':IfSimI,\ #'SimInfo':p1.SimInfo.id,\ #'Owner':p1.Owner,\ 'HealthState':p1.HealthState,\ 'About':p1.About,\ 'MemoryInfo':p1.MemoryInfo.id }, ) return render_to_response('Device_mod.html',{'form':form,\ 'PhoneInfo_mod_result':PhoneInfo_mod_result,\ 'p_id':id_i},\ context_instance = RequestContext(request)) else: return HttpResponseRedirect('/msg?t=缺少相关操作权限')
def DeviceMaintainMgr_Add(request): user = request.user if user.username == 'admin' or user.has_perm('PhoneMgr.DeviceMaintain_AddNewDevice'): PhoneInfo_add_result = '' if request.method == 'POST': form = PhoneInfoQue(request.POST) if form.is_valid(): cd = form.cleaned_data #print cd #print SimInfo.objects.get(id = 2) #这里添加数据 CurrState = 0 if int(cd['Owner']) == 0: owner = None CurrState = 11 else: owner = User.objects.get(id = int(cd['Owner'])) CurrState = 11 p1 = PhoneInfo(PhoneName=cd['PhoneName'],\ ProductInfo=ProductInfo.objects.get(id= int(cd['ProductInfo'])),\ #ModelInfo=ModelInfo.objects.get(id = int(cd['ModelInfo'])),\ OsInfo=OsInfo.objects.get(id = int(cd['OsInfo'])),\ OsVersionInfo=OsVersionInfo.objects.get(id = int(cd['OsVersionInfo'])),\ CpuType = cd['CpuType'],\ CpuCoreNum = int(cd['CpuCoreNum']),\ ScreenSizeInfo = ScreenSizeInfo.objects.get(id = int(cd['ScreenSizeInfo'])), ResolutionInfo=ResolutionInfo.objects.get(id = int(cd['ResolutionInfo'])),\ MemoryInfo=MemoryInfo.objects.get(id = int(cd['MemoryInfo'])),\ IMEI=cd['IMEI'],\ #IfSim=int(cd['IfSim']),\ #SimInfo=SimInfo.objects.get(id = int(cd['SimInfo'])),\ #健康状态默认正常 HealthState = 0,\ IfTel = int(cd['IfTel']),\ Owner=owner,\ CurrState = CurrState,\ FundId=cd['FundId'],\ About = cd['About'],\ CreateDate=int(time.time()),\ UpdateDate=int(time.time()) ) #print p1 try: p1.save() except Exception,e: PhoneInfo_add_result = '[设备维护]添加数据失败!' #traceback.print_exc() #print e else: PhoneInfo_add_result = '添加成功' #添加成功后在手机状态表中添加一条记录 #if p1.Owner is None: #没有归属人 # p2 = PhoneCurrState(PhoneInfo=p1,\ # CurrState=0) #else: # p2 = PhoneCurrState(PhoneInfo=p1,\ # CurrState=1) #p2.save() p2 = PhoneHisState(PhoneInfo=p1,CurrState = CurrState,CreateDate=int(time.time())) p2.save() #保存日志记录 SaveLog(user,1001,p1,1) return HttpResponseRedirect('/msg?t='+PhoneInfo_add_result) else: form = PhoneInfoQue() return render_to_response('Device_add.html',{'form':form,'PhoneInfo_add_result':PhoneInfo_add_result},\ context_instance = RequestContext(request))