本文整理汇总了Python中usermanagement.utils.RequestValidator类的典型用法代码示例。如果您正苦于以下问题:Python RequestValidator类的具体用法?Python RequestValidator怎么用?Python RequestValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestValidator类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: dispatch
def dispatch(self,request, *args, **kwargs):
me = RequestValidator(request.META)
if me.user_is_exist():
return super(DiscoveryRuleDetailList, self).dispatch(request,*args, **kwargs)
else:
resp = me.invalid_token()
return JsonResponse(resp,status=status.HTTP_400_BAD_REQUEST)
开发者ID:senglobe,项目名称:ignite,代码行数:7,代码来源:views.py
示例2: put
def put(self, request, id, format=None):
me = RequestValidator(request.META)
discoveryrule=self.get_object(id)
if request.data['match']!='serial_id':
serializer = DiscoveryRulePutSerializer(data=request.data)
if serializer.is_valid():
rule_object = self.get_object(id)
subrules = json.dumps(serializer.data['subrules'])
rule_object.subrules = subrules
rule_object.priority = serializer.data['priority']
rule_object.user_id = me.user_is_exist().user_id
rule_object.config_id = serializer.data['config_id']
rule_object.match = serializer.data['match'].lower()
rule_object.save()
serializer = DiscoveryRuleGetDetailSerializer(rule_object)
resp = serializer.data
resp['subrules'] = json.loads(resp['subrules'])
return Response(resp)
else:
serializer = DiscoveryRuleIDPutSerializer(data=request.data)
if serializer.is_valid():
rule_object = self.get_object(id)
for i in range(len(serializer.data['subrules'])):
serializer.data['subrules'][i]=str(serializer.data['subrules'][i])
subrules = str(serializer.data['subrules'])
rule_object.subrules = subrules
rule_object.priority = serializer.data['priority']
rule_object.user_id = me.user_is_exist().user_id
rule_object.config_id = serializer.data['config_id']
rule_object.match = serializer.data['match'].lower()
rule_object.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:senglobe,项目名称:ignite,代码行数:33,代码来源:views.py
示例3: post
def post(self, request, format=None):
me = RequestValidator(request.META)
if request.data['match']!='serial_id':
serializer = DiscoveryRuleSerializer(data=request.data)
if serializer.is_valid():
rule_object = DiscoveryRule()
rule_object.name = serializer.data['name']
rule_object.priority = serializer.data['priority']
rule_object.user_id = me.user_is_exist().user_id
rule_object.config_id = serializer.data['config_id']
rule_object.subrules = json.dumps(serializer.data['subrules'])
rule_object.match = serializer.data['match'].lower()
rule_object.save()
serializer = DiscoveryRuleGetSerializer(rule_object)
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
serializer = DiscoveryRuleSerialIDSerializer(data=request.data)
if serializer.is_valid():
rule_object = DiscoveryRule()
rule_object.name = serializer.data['name']
rule_object.priority = serializer.data['priority']
rule_object.user_id = me.user_is_exist().user_id
rule_object.config_id = serializer.data['config_id']
for i in range(len(serializer.data['subrules'])):
serializer.data['subrules'][i]=str(serializer.data['subrules'][i])
rule_object.subrules = str(serializer.data['subrules'])
rule_object.match = serializer.data['match']
rule_object.save()
serializer = DiscoveryRuleGetSerializer(rule_object)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:senglobe,项目名称:ignite,代码行数:31,代码来源:views.py
示例4: put
def put(self, request, id, format=None):
success = True
resp = {}
resp['Error'] = ' '
fabric_obj = self.get_object(id)
topology_id = fabric_obj.topology.id
serializer = FabricPutSerializer(data=request.data)
if serializer.is_valid():
if ((request.data['topology_id'] != topology_id) or (fabric_obj.name != request.data['name'])):
logger.error("Failed to Update Fabric id " + str(id)\
+" cannot change base Topology or Fabric Name")
else:
topology = Topology.objects.get(id=request.data['topology_id'])
topology_json = json.loads(topology.topology_json)
me = RequestValidator(request.META)
fabric_obj.user_id = me.user_is_exist().user_id
fabric_obj.validate = request.data['validate']
fabric_obj.locked = request.data['locked']
find_dup_data = {'system_id':['system_id','name'], 'config_json':['name']}
for key,val in find_dup_data.iteritems():
for value in val:
err_msg, isError = findDuplicate(request.data[key], value)
if isError:
resp['Error'] = err_msg
return Response(resp, status=status.HTTP_400_BAD_REQUEST)
err = uniqueSystenmId(request.data['system_id'], fabric_obj.id)
if err !="":
resp['Error'] = err
return Response(resp, status=status.HTTP_400_BAD_REQUEST)
config_in_fabric = json.loads(fabric_obj.config_json)
for config in config_in_fabric:
config_obj = Configuration.objects.get(id = config['configuration_id'])
config_obj.used -= 1
config_obj.save()
fabric_obj.config_json = json.dumps(request.data['config_json'])
for config in request.data['config_json']:
config_obj = Configuration.objects.get(id = config['configuration_id'])
config_obj.used += 1
config_obj.save()
fabric_obj.submit = request.data['submit']
fabric_obj.instance = request.data['instance']
# filling image details
try:
fabric_obj.image_details = json.dumps(request.data['image_details'])
except:
pass
# filling profiles
"""
try:
fabric_obj.profiles = json.loads(request.data['profiles'])
except:pass
"""
# filling discovery rule db
try:
DiscoveryRule.objects.filter(fabric_id=id).delete()
except:
logger.error('Failed to delete Discovery rules with fabric_id:'+str(id))
resp['Error'] = ['Failed to delete Discovery rules']
return Response(resp, status=status.HTTP_400_BAD_REQUEST)
success, resp, dis_bulk_obj = add_dis_rule(request.data,success,resp,fabric_obj.id)
if success:
if delete_fabric_rules(id):
if (generate_fabric_rules(request.data['name'],\
request.data['instance'], fabric_obj, request.data['config_json'],\
topology_json)):
logger.info("Successfully update Fabric id: " + str(id))
serializer = FabricGetDetailSerializer(fabric_obj)
data = serializer.data
data['config_json'] = json.loads(data['config_json'])
try:
data['system_id'] = json.loads(data['system_id'])
except:
data['system_id'] = []
try: # image details
data['image_details'] = json.loads(data['image_details'])
except:
data['image_details'] = []
for obj in dis_bulk_obj:
obj.save()
fabric_obj.save()
return Response(data)
else:
success = False
resp['Error'] = 'Failed to update Fabric'
logger.error("Failed to update Fabric id: " + str(id))
else:
success = False
resp['Error'] = 'Failed to update Fabric Rule DB'
logger.error("Failed to delete Rules from fabric Rule DB for Fabric id: " + str(id))
if not success:
return Response(resp, status=status.HTTP_400_BAD_REQUEST)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:javaos74,项目名称:ignite,代码行数:94,代码来源:views.py
示例5: post
def post(self, request, format=None):
success = True
resp = {}
resp['Error'] = ' '
serializer = FabricSerializer(data=request.data)
topology = Topology.objects.get(id=request.data['topology_id'])
topology_json = json.loads(topology.topology_json)
me = RequestValidator(request.META)
if serializer.is_valid():
if request.data['instance'] < 1:
logger.error("Fabric Instances cannot be less than 1")
else:
fabric_obj = Fabric()
find_dup_data = {'system_id':['system_id','name'], 'config_json':['name']}
for key,val in find_dup_data.iteritems():
for value in val:
err_msg, isError = findDuplicate(request.data[key], value)
if isError:
resp['Error'] = err_msg
return Response(resp, status=status.HTTP_400_BAD_REQUEST)
err = uniqueSystenmId(request.data['system_id'],fabric_obj.id)
if err != "":
resp['Error'] = err
return Response(resp, status=status.HTTP_400_BAD_REQUEST)
fabric_obj.name = request.data['name']
fabric_obj.user_id = me.user_is_exist().user_id
fabric_obj.topology = topology
topology.used += 1
topology.save()
fabric_obj.instance = request.data['instance']
fabric_obj.validate = request.data['validate']
fabric_obj.locked = request.data['locked']
fabric_obj.config_json = json.dumps(request.data['config_json'])
for config in request.data['config_json']:
config_obj = Configuration.objects.get(id = config['configuration_id'])
config_obj.used += 1
config_obj.save()
fabric_obj.submit = request.data['submit']
try:
fabric_obj.system_id = json.dumps(request.data['system_id'])
except:
fabric_obj.system_id = []
"""
try:
fabric_obj.profiles = json.dumps(request.data['profiles'])
except:
fabric_obj.profiles = json.dumps({})
"""
try: # fill image details
fabric_obj.image_details = json.dumps(request.data['image_details'])
except:
fabric_obj.image_details = json.dumps({})
try: # save object
fabric_obj.save()
except:
logger.error("Failed to create Fabric: " + fabric_obj.name)
resp['Error'] = 'Failed to create Fabric'
return JsonResponse(resp,status=status.HTTP_400_BAD_REQUEST)
# filling discovery rule with system_id
success, resp, dis_bulk_obj = add_dis_rule(request.data,success,resp,fabric_obj.id)
if success:
if (generate_fabric_rules(request.data['name'],\
request.data['instance'], fabric_obj, request.data['config_json'],\
topology_json)):
serializer = FabricGetSerializer(fabric_obj)
logger.info("Successfully created Fabric id: " + str(fabric_obj.id))
try:
for obj in dis_bulk_obj:
obj.save()
except:
logger.error('failed to save dis_rule_obj')
resp['Error']='Failed to save DiscoveryRules'
return JsonResponse(resp,status=status.HTTP_400_BAD_REQUEST)
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
success = False
logger.error("Failed to update FabricRuleDb: " + fabric_obj.name)
resp['Error'] = 'Failed to update FabricRule DB'
if not success:
try:
DiscoveryRule.objects.filter(fabric_id = fabric_obj.id).delete()
except:
pass
Fabric.objects.filter(id = fabric_obj.id).delete()
logger.error("Failed to create Fabric: " + fabric_obj.name)
return JsonResponse(resp,status=status.HTTP_400_BAD_REQUEST)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:javaos74,项目名称:ignite,代码行数:93,代码来源:views.py
注:本文中的usermanagement.utils.RequestValidator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论