def post(self, request):
        _id = request.POST.get('id')
        status = False

        try:
            obj = models.SysModule.objects.filter(id=_id)
            if obj.count() > 0:
                obj.delete()
                status = True
                Logger.important(request, '删除了ID为%s的模块记录数据' % _id)
        except Exception as error:
            Logger.error(request,
                         '删除ID为%s的模块记录数据时出现错误:%s' % (_id, error.__str__()))
            status = error.__str__()

        return HttpResponse(status)
	def post(self, request):
		_all = request.POST.get('all')
		page = request.POST.get('page')
		limit = request.POST.get('limit')
		_type = request.POST.get('type')
		_filter = request.POST.get('filter')
		queryDict = request.POST.dict()
		begin, end = basicUtils.pageHandle(page, limit)

		for item in notDbField:
			# 剔除与数据库无关字段
			if queryDict.get(item) == None:
				continue
			queryDict.pop(item)

		status = 500
		msg = ''
		count = 0
		returnData = {}
		_models = ''
		data = []

		try:
			if type(_type) == str:
				if _type.lower() == 'staffs':
					_models = models.SysStaff.objects
				elif _type.lower() == 'department':
					_models = models.SysDepartment.objects

				obj = GetModelData(_models, all = _all, isFilter = _filter, queryDict = queryDict)

				count = obj.count

				staffData = obj.data[begin:end]
				for item in staffData:
					itemDict = model_to_dict(item)
					data.append(itemDict)
				status = 200
		except Exception as error:
			Logger.error(request, '访问员工/部门数据列表页时出现错误:%s' % error.__str__())
			msg = error.__str__()

		returnData['status'] = status
		returnData['msg'] = msg
		returnData['count'] = count
		returnData['data'] = data
		return JsonResponse(returnData)
    def get(self, request, id):
        HTTP_REFERER = request.META.get('HTTP_REFERER')
        if not HTTP_REFERER:
            return HttpResponse('非法请求')

        returnData = {}
        try:
            obj = models.SysModule.objects.get(id=id)
            returnData = model_to_dict(obj)
        except Exception as error:
            Logger.error(request, '请求更新模块数据页面时出现错误:%s' % error.__str__())

        return render(request,
                      'controlPanel/systemSettings/methods/updateModule.html',
                      {
                          'data': returnData,
                      })
    def post(self, request):
        status = False
        queryDict = request.POST.dict()
        try:
            userData = request.session.get('userData')
            userObj = models.SysUsers.objects.get(id=userData.get('id'))
            if queryDict.get('curr_passwd') == userObj.password:
                if queryDict.get('new_passwd1') == queryDict.get(
                        'new_passwd2'):
                    userObj.password = queryDict.get('new_passwd1')
                    userObj.save()
                    del request.session['userData']
                    status = True
        except Exception as error:
            Logger.error(request, '修改密码时出现错误:%s' % error.__str__())

        return HttpResponse(status)
    def post(self, request, id):
        user_id = id
        returnData = {}
        code = 0
        msg = ''
        data = {}
        _list = []
        try:
            obj = models.SysModule.objects.filter()\
            .annotate(name = F('module_alias'), pid = F('parent_id'))\
            .values('id', 'pid', 'module_name', 'name', 'module_link', 'module_desc')

            for item in obj:
                item['children'] = []
                _list.append(item)
            msg = '获取成功'

            # 获取当前用户用户的权限
            if id:
                userAuthObj = models.SysAuth.objects.get(user_id=user_id)
                if userAuthObj.auth_group_status == 1 or userAuthObj.auth_group_status == '1':
                    # 如果当前用户继承组权限则返回该用户组的权限集合
                    userObj = models.SysUsers.objects.get(
                        id=userAuthObj.user_id)
                    userGroupAuthObj = models.SysAuthGroup.objects.get(
                        auth_group_id=userObj.user_group)
                    authCodeStrList = (userGroupAuthObj.auth_code).split(',')
                    data['extendGroup'] = userAuthObj.auth_group_status
                else:
                    # 如果该用户不继承组权限则获取自己的权限
                    data['extendGroup'] = userAuthObj.auth_group_status
                    authCodeStrList = (userAuthObj.auth_code).split(',')

                data['checkedId'] = list(map(int, authCodeStrList))

        except Exception as error:
            Logger.error(request, '获取模块树结构时出现错误:%s' % error.__str__())
            code = 500
            msg = error.__str__()

        data['list'] = _list
        returnData['code'] = code
        returnData['msg'] = msg
        returnData['data'] = data
        return JsonResponse(returnData)
	def post(self, request):
		status = False
		queryDict = request.POST.dict()

		try:
			for item in notDbField:
				if item in queryDict:
					queryDict.pop(item)

			if queryDict:
				newId = models.SysDepartment.objects.create(**queryDict)
				if newId:
					status = True
					Logger.important(request, '添加了新部门信息, 新增记录数据ID为:%s' % newId.id)
		except Exception as error:
			Logger.error(request, '添加新部门信息时出现错误:%s' % error.__str__())

		return HttpResponse(status)
	def post(self, request):
		try:
			page = request.POST.get('page')
			limit = request.POST.get('limit')
			_filter = request.POST.get('filter')
			listQuery = request.POST.get('list')
			queryDict = request.POST.dict()

			for item in ['csrfmiddlewaretoken', 'page', 'limit']:
				# 剔除非数据库数据
				if queryDict.get(item):
					queryDict.pop(item)

			begin, end = basicUtils.pageHandle(page, limit)
			returnData = {}
			data = []

			FilterObj = ListFilter()
			FilterObj.init(models = models.SysAssetPhone.objects, queryDict = queryDict, isFilter = _filter, isListQuery = listQuery)

			assetData = FilterObj.data[begin:end]

			if FilterObj.count <= int(limit):
				# 如果筛选之后数据量小于分页值则返回未切片的所有数据
				assetData = FilterObj.data

			for item in assetData:
				item.use_user = item.use_user + item.english_name
				data.append(model_to_dict(item))

			status = 200
			msg = ''

		except Exception as error:
			Logger.error(request, '手机资产列表页获取数据时出现错误:%s' % error.__str__())
			status = 500
			msg = error.__str__()

		returnData['status'] = status
		returnData['msg'] = msg
		returnData['count'] = FilterObj.count
		returnData['data'] = data

		return JsonResponse(returnData)
示例#8
0
    def post(self, request):
        _status = request.POST.get('status')
        queryDict = request.POST.dict()
        status = False

        try:
            obj = SetStatus(queryDict, request)
            FuncObj = getattr(obj, _status)
            status = FuncObj()
            if status:
                Logger.important(
                    request, '设置了编号为%s的待采购商品%s状态' %
                    (queryDict.get('purchase_id'), _status))
        except Exception as error:
            print(error)
            status = False
            Logger.error(request, '设置待采购商品状态时出现错误:%s' % error.__str__())

        return HttpResponse(status)
	def post(self, request, type):
		try:
			deviceType = int(request.POST.get('deviceType'))
			deviceName = request.POST.get('deviceName')
			newObj = ''
			if deviceType == '' or deviceName == '':
				return HttpResponse(False)

			if type == 'add':
				if deviceType == 1:
					newObj = models.SysPcMainboard.objects.create(name = deviceName)
				elif deviceType == 2:
					newObj = models.SysPcCpu.objects.create(name = deviceName)
				elif deviceType == 3:
					newObj = models.SysPcHarddisk.objects.create(name = deviceName)
				elif deviceType == 4:
					newObj = models.SysPcDisplaycard.objects.create(name = deviceName)
				elif deviceType == 5:
					newObj = models.SysPcDisplay.objects.create(name = deviceName)
				elif deviceType == 6:
					newObj = models.SysPcMemory.objects.create(name = deviceName)

			if type == 'delete':
				if deviceType == 1:
					models.SysPcMainboard.objects.filter(id = deviceName).delete()
				elif deviceType == 2:
					models.SysPcCpu.objects.filter(id = deviceName).delete()
				elif deviceType == 3:
					models.SysPcHarddisk.objects.filter(id = deviceName).delete()
				elif deviceType == 4:
					models.SysPcDisplaycard.objects.filter(id = deviceName).delete()
				elif deviceType == 5:
					models.SysPcDisplay.objects.filter(id = deviceName).delete()
				elif deviceType == 6:
					models.SysPcMemory.objects.filter(id = deviceName).delete()

			Logger.important(request, '%s设备记录数据, 设备ID为:%s' % (type, newObj.id if newObj else deviceName))
			return HttpResponse(True)
		except Exception as error:
			Logger.error(request, '%s设备记录数据时出现错误:%s' % (type, error.__str__()))

		return HttpResponse(False)
示例#10
0
    def post(self, request):
        page = request.POST.get('page')
        limit = request.POST.get('limit')
        _all = request.POST.get('all')
        begin, end = basicUtils.pageHandle(page, limit)

        generaterObj = basicUtils.GenerateReturnData()
        try:
            if _all == 'true':
                data = models.SysAuthGroup.objects.all().order_by('id')
                if data.count() > 0:
                    generaterObj.setData(data[begin:end])
                    generaterObj.setCount(data.count())

        except Exception as error:
            Logger.error(request, '访问用户权限管理页时出现错误:%s' % error.__str__())
            generaterObj.setMsg(error.__str__())
            generaterObj.setStatus(500)

        return JsonResponse(generaterObj.generate())
示例#11
0
    def post(self, request):
        account = request.POST.get('account').strip()
        password = request.POST.get('password').strip()
        info = {}
        flag = False
        info['state'] = flag
        if account == '' or password == '':
            info['msg'] = '用户名及密码不能为空'
            return JsonResponse(info)

        if account != '' or password != '':
            try:
                userObj = models.SysUsers.objects.get(username=account,
                                                      password=password)
                if userObj.user_status == 1 or userObj.user_status == '1':
                    # 如果用户状态为0则为禁用状态无法登录
                    userObj.last_time = time()
                    userObj.save()
                    userData = model_to_dict(userObj)

                    userGroupObj = models.SysUserGroup.objects.filter(
                        group_level=userData.get('user_group')).values(
                            'id', 'group_name', 'group_level',
                            'desc')[0]  # 用户组对象
                    userData.update(userGroupObj)

                    userData.pop('password')
                    userData.pop('security_password')
                    request.session['userData'] = userData
                    flag = True
                    Logger.info(request, '登录后台系统')
                else:
                    info['msg'] = '该用户已被禁用, 无法登录'

            except Exception as error:
                info['msg'] = '用户名或密码错误'
                Logger.error(request,
                             '%s登录系统后台出现错误:%s' % (account, error.__str__()))

        info['state'] = flag
        return JsonResponse(info)
示例#12
0
    def post(self, request, id):
        HTTP_REFERER = request.META.get('HTTP_REFERER')
        if not HTTP_REFERER:
            return HttpResponse('非法请求')

        status = False
        _id = request.POST.get('id')
        queryDict = request.POST.dict()
        queryDict = basicUtils.removeNotDbField(queryDict)
        queryDict.pop('id')

        try:
            obj = models.SysModule.objects.filter(id=_id)
            if obj.count() > 0:
                obj.update(**queryDict)
                status = True
                Logger.important(request, '更新了模块ID为:%s的记录数据' % _id)
        except Exception as error:
            Logger.error(request, '编辑更新模块时出现错误:%s' % error.__str__())

        return HttpResponse(status)
示例#13
0
	def post(self, request):
		page = request.POST.get('page')
		returnData = {}
		data = []

		try:
			if page == 'asset':
				obj = models.SysAsset.objects.all().order_by('id')

			if page == 'phone':
				obj = models.SysAssetPhone.objects.all().order_by('id')

			if obj.count() > 0:
				for item in obj:
					data.append(model_to_dict(item))

		except Exception as error:
			Logger.error(request, '在%s页面导出excel表格时出现错误:%s' % (_type, error.__str__()))

		returnData['data'] = data
		return JsonResponse(returnData)
示例#14
0
    def post(self, request):
        status = False
        groupId = request.POST.get('auth_group_id')
        queryDict = request.POST.dict()
        authIds = []
        try:
            for key, value in queryDict.items():
                if 'authids' in key:
                    authIds.append(value)

            authIds = list(map(int, authIds))
            authIds.sort(reverse=False)
            authCode = str(authIds).strip('[]').replace(' ', '')
            models.SysAuthGroup.objects.filter(auth_group_id=groupId).update(
                auth_code=authCode)
            status = True
            Logger.important(request, '编辑了ID为%s的用户组权限' % groupId)
        except Exception as error:
            Logger.error(request, '编辑ID为%s的用户组权限时出现错误:%s' % error.__str__())
            status = error.__str__()

        return HttpResponse(status)
示例#15
0
    def post(self, request, method):
        queryDict = request.POST.dict()
        status = False

        try:
            for item in notDbField:
                # 剔除与数据库无关字段
                if item not in queryDict:
                    continue
                queryDict.pop(item)

            obj = UserManageMethodsMain(models.SysUsers.objects,
                                        queryDict=queryDict)
            Func = getattr(obj, method)
            status = Func()

            Logger.important(request,
                             '%s系统用户:%s' % (method, queryDict.get('id')))
        except Exception as error:
            Logger.error(request, '%s系统用户时出现错误:%s' % (method, error.__str__()))

        return HttpResponse(status)
示例#16
0
	def post(self, request):
		status = False

		queryDict = request.POST.dict()
		if queryDict.get('batch') == 'true':
			idList = request.POST.getlist('id')
			queryDict['id'] = idList

		method = queryDict.get('method')
		try:
			queryDict.pop('method')
			queryDict.pop('csrfmiddlewaretoken')

			if method:
				obj = RepMethods()
				Func = getattr(obj, method)
				status = Func(queryDict)

				Logger.important(request, '%s仓库资产ID为%s的记录数据' % (method, queryDict.get('id')))
		except Exception as error:
			Logger.error(request, '%s仓库资产ID为%s的记录数据时出现错误:%s' % (method, queryDict.get('id'), error.__str__()))

		return HttpResponse(status)
示例#17
0
	def post(self, request, page, type):
		method = request.POST.get('method')
		if method == 'batch':
			data = request.POST.getlist('id')
		else:
			data = request.POST.dict()
			data.pop('csrfmiddlewaretoken')

		state = False
		try:
			methodObj = AssetDeleteAndUpdateMethod()
			page = page if page else 'asset'
			func = getattr(methodObj, page, None)
			func(type, data)

			state = True
			Logger.important(request, '在%s列表页%s资产ID为%s的数据记录' % (page, type, data.get('id')))
		except Exception as error:
			Logger.error(request, '在%s列表页%s资产ID为%s的出现错误:%s' % (page, type, data.get('id'), error.__str__()))
			print(error)
			pass

		return HttpResponse(state)
示例#18
0
    def post(self, request):
        queryDict = request.POST.dict()
        userId = queryDict.get('user_id')
        extendGroup = queryDict.get('extendGroup')  # 勾选了继承组权限
        authIds = []
        status = False
        try:
            auth_group_status = models.SysAuth.objects.get(
                user_id=userId).auth_group_status
            if extendGroup == '1' or extendGroup == 1:
                if auth_group_status == 1:
                    raise RuntimeError('该用户已继承组权限, 无法单独修改权限')
                else:
                    models.SysAuth.objects.filter(user_id=userId).update(
                        auth_group_status=1)
                    return HttpResponse(True)
            elif auth_group_status == 1:
                models.SysAuth.objects.filter(user_id=userId).update(
                    auth_group_status=0)

            for key, value in queryDict.items():
                if 'authids' in key:
                    authIds.append(value)

            authIds = list(map(int, authIds))
            authIds.sort(reverse=False)
            authCode = str(authIds).strip('[]').replace(' ', '')
            models.SysAuth.objects.filter(user_id=userId).update(
                auth_code=authCode)
            status = True
            Logger.important(request, '编辑了ID为%s的用户权限' % userId)
        except Exception as error:
            Logger.error(request,
                         '编辑ID为%s的用户权限时出现错误:%s' % (userId, error.__str__()))
            status = error.__str__()

        return HttpResponse(status)
示例#19
0
    def post(self, request):
        status = False
        queryDict = request.POST.dict()
        queryDict.pop('csrfmiddlewaretoken')

        try:
            imageFile = request.FILES.get('image')
            if imageFile:
                if imageFile.size > (5 * 1024 * 1024):
                    return HttpResponse('上传的文件大小不得大于5M')

                fileName, dirName = basicUtils.fileWrite(imageFile.name,
                                                         fileStream=imageFile,
                                                         isImage=True,
                                                         mkdir=True,
                                                         hashFileName=True)
                queryDict['image_name'] = fileName
                queryDict['image_dir'] = dirName

            queryDict['create_time'] = basicUtils.getDatetimeNow()
            queryDict[
                'importance_status_text'] = settings.IMPORTANCE_STATUS_TEXT.get(
                    queryDict.get('importance_status'))
            queryDict['buy_status'] = 0
            queryDict['buy_process'] = 0
            queryDict['save_status'] = 0

            newObj = models.SysPurchase.objects.create(**queryDict)
            Logger.warning(
                request,
                '创建了新采购项, 新采购项ID:%s, 编号:%s' % (newObj.id, newObj.purchase_id))
            status = True
        except Exception as error:
            print(error)
            Logger.error(request, '创建新待采购项时出现错误:%s' % error.__str__())

        return HttpResponse(status)
示例#20
0
    def post(self, request):
        _all = request.POST.get('all')
        queryDict = request.POST.dict()
        returnData = {}
        msg = ''
        data = []

        try:
            page = int(request.POST.get('page'))

            if _all == 'true':
                obj = models.SysPurchase.objects.filter(
                    save_status=0).order_by('-create_time')
                if page == 1:
                    # 用于layui流加载, 当前页为1时默认加载4个
                    obj = obj[0:4]
                elif page > 1:
                    # 当前页大于1时则只加载2个
                    begin = page * 2
                    end = begin + 2
                    obj = obj[begin:end]
            else:
                _id = queryDict.get('id')
                obj = models.SysPurchase.objects.filter(
                    id=_id).order_by('-create_time')

            for item in obj:
                data.append(model_to_dict(item))

        except Exception as error:
            Logger.error(request, '获取待采购物品记录时出现错误:%s' % error.__str__())
            msg = error.__str__()

        returnData['msg'] = msg
        returnData['data'] = data

        return JsonResponse(returnData)
示例#21
0
def pageError(request):
    '''
	500页面
	'''
    Logger.error(request, '访问地址出现500:%s' % request.path)
    return render(request, 'error/500.html')
示例#22
0
def pageNotFound(request):
    '''
	404页面
	'''
    Logger.error(request, '访问地址出现404:%s' % request.path)
    return render(request, 'error/404.html')