@csrf_exempt @validate_session def submitBvrFormAdd(request): print request.body print "\nFUNCTION( submitFormAdd ) User : "+str(request.user) context = RequestContext(request) context.user = request.user user = '' role = '' token = '' try: #Get Token to Authenticate OpenAM: if request.COOKIES.has_key("iPlanetDirectoryPro"): token = str(copy.deepcopy(request.COOKIES['iPlanetDirectoryPro'])) #User Role and User Name Details: userDetails = userAttributes( request, token)#, userName) user = userDetails['userName'] role = userDetails['role'] #Added TO Check with SSO: request.user = user context.user = request.user #Get State Of the USER: process_state = 'TN' FORM_DATA = '' if "form_data" in request.POST: formData = request.POST["form_data"] FORM_DATA = json.loads(formData) #Saving Image function and defining a location to save IMAGES: data = updateImage(FORM_DATA, request) import io #AVRO SCHEMA LOAD FOR MEMBER LOAN COMPOSITE: schema = avro.schema.parse( open(settings.SCHEMA_LOCATION+"businessverificationschema.avsc").read() ) writer = avro.io.DatumWriter(schema) bytes_writer = io.BytesIO() encoder = avro.io.BinaryEncoder(bytes_writer) #ENCODE DATA writer.write( data , encoder) print bytes_writer.getvalue() try: #url = 'http://'+settings.API_IP_AVRO+'/madura-coreservice/rest/api/addmlcomposite/mlcomposite' url = 'http://'+settings.API_IP_AVRO+'madura-coreservice/rest/api/addbuzverify/buzverification/details' print url byte_data = bytes_writer.getvalue() request1 = urllib2.Request( url , bytes_writer.getvalue() ) request1.add_header( 'Content-Type' , 'avro/binary' ) request1.get_method = lambda: 'POST' result1 = urllib2.urlopen( request1 ) serialized_data = io.BytesIO( result1.read() ) print serialized_data try: response_schema = avro.schema.parse( open(settings.SCHEMA_LOCATION+"responseschema.avsc").read()) #response_schema) decoder = avro.io.BinaryDecoder(serialized_data) reader = avro.io.DatumReader(response_schema) response = reader.read(decoder) print response response["message"]="Success" distributorUid = str( request.user ) appStatus = "New" memberId = 0 loanId = 0 if 'member_id' in response: memberId= response['member_id'] if 'loan_id' in response: loanId = response['loan_id'] processStart = { "variables": { "State" : {"value" : ""+ str(process_state)+"" ,"type": "String" }, "DistributorUid" : {"value" : ""+ str(distributorUid)+"" , "type": "String"}, "Application_Status" : {"value" : ""+ str(appStatus) +"" , "type": "String"}, "MemberId" : {"value" : ""+ str(memberId) +"" , "type": "Long" }, "LoanId" : {"value" : ""+ str(loanId) +"" , "type": "Long" }, "Application_Remarks" : {"value" : "","type": "String"}, "CB_Request_Status" : {"value" : "","type": "String"}, "Approval_Status" : {"value" : "","type": "String"}, "Pre_Approval_Flag" : {"value" : "","type": "String"}, "CB_Remarks" : {"value" : "","type": "String"}, "KALoanDoc_Upload_Status" : {"value" : "","type": "String"}, "KALoanDoc_Verify_Status" : {"value" : "","type": "String"}, "KALoanDoc_Remarks" : {"value" : "","type": "String"}, "LoanDoc_Verify_Status" : {"value" : "","type": "String"}, "LoanDoc_Remarks" : {"value" : "","type": "String"}, "LoanDoc_Physical_Status" : {"value" : "","type": "String"}, "LoanDoc_Physical_Remarks" : {"value" : "","type": "String"}, "LoanDoc_Aknow_Status" : {"value" : "","type": "String"}, "ChequeId" : {"value" : "","type": "String"}, "LoanCheque_Approve_Status" : {"value" : "","type": "String"}, "LoanCheque_Aknow_Status" : {"value" : "","type": "String"} }, "businessKey" : "retailLoanProcess" } try: if response['status'] == "Successful" and response['member_id'] != None and response['loan_id'] != None : print "Inside Start Process: " url_start_process = 'http://'+settings.API_IP_CAMUNDA+'/engine-rest/process-definition/key/VVLProcess/start' request2 = urllib2.Request(url_start_process, json.dumps(processStart) ) request2.add_header('Content-Type', 'application/json') result2 = urllib2.urlopen(request2) Read_data = result2.read() print Read_data return HttpResponse( json.dumps( response ), content_type="application/json" ) except Exception as e: print "\nEXCEPTION inside submitFormAdd--> Start process- api response 1 : %s" %e return HttpResponse( json.dumps( {"message":"Start process Failed"} ), content_type="application/json" ) except Exception as e: print "\nEXCEPTION inside submitFormAdd--> response of Member creation API reader - api response 1 : %s" %e return HttpResponse( json.dumps( {"message":"Failed"} ), content_type="application/json" ) except Exception as e: print "\nEXCEPTION inside submitFormAdd--> response of Member creation API - api call : %s" %e return HttpResponse( json.dumps( {"message":"Failed"} ), content_type="application/json" ) except Exception as e: print "EXCEPTION inside submitFormAdd-->Main :: %s" % e return HttpResponse( json.dumps( {"message":"Failed"} ), content_type="application/json" )
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question