def sample06(request): if request.content_type != 'application/json': return render_to_response('__main__:templates/sample06.pt', { }) #Request to json jsonPostData = request.json_body # import pdb; pdb.set_trace() #Get parameters clientId = jsonPostData["userId"] privateKey = jsonPostData["privateKey"] documents = jsonPostData['documents'] signers = jsonPostData['signers'] #Checking parameters if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(documents) == False or IsNotNull(signers) == False: return render_to_response('__main__:templates/sample06.pt', { 'error' : 'You do not enter you User id or Private key' }) #Determination of placeSignatureOn parameter for i, signer in enumerate(signers): signers[i]['placeSignatureOn'] = '' ####Create Signer, ApiClient and Storage Api objects #Create signer object signerReq = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signerReq) #Create Signsture API object signatureApi = SignatureApi(apiClient) #Create setting variable for signature SignDocument method settings = SignatureSignDocumentSettingsInfo() settings.documents = documents settings.signers = signers ####Make a request to Signature Api for sign document #Sign document using current user id and sign settings response = signatureApi.SignDocument(clientId, body = settings) #If request was successfull - set variables for template error = '' if response.status == 'Ok': time.sleep(5) getDocumentStatus = signatureApi.GetSignDocumentStatus(clientId, response.result.jobId); if getDocumentStatus.status == "Ok": guid = getDocumentStatus.result.documents[0].documentId iframe = 'https://apps.groupdocs.com/document-viewer/embed/' + guid iframe = signerReq.signUrl(iframe) return_data = json.dumps({ 'responseCode' : 200, 'url' : iframe }) return Response(body = return_data, content_type = 'application/json') else: error = getDocumentStatus.error_message return render_to_response('__main__:templates/sample06.pt', { 'error' : response.error_message }) else: error = response.error_message return render_to_response('__main__:templates/sample06.pt', { 'error' : response.error_message })
def sample39(request): #Check if data posted #Check is document should be signed with widget if email is not in post data - sign document with widget if request.content_type == 'application/json': #Get parameters jsonPostData = request.json_body clientId = jsonPostData["userId"] privateKey = jsonPostData["privateKey"] documents = jsonPostData['documents'] signers = jsonPostData['signers'] error = None #Checking parameters if not clientId or not privateKey or not documents or not signers: error = 'You do not enter you User id or Private key' #Determination of placeSignatureOn parameter for i, signer in enumerate(signers): signers[i]['placeSignatureOn'] = '' ####Create Signer, ApiClient and Storage Api objects #Create signer object signerReq = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signerReq) #Create Signature API object signatureApi = SignatureApi(apiClient) #Create setting variable for signature SignDocument method settings = SignatureSignDocumentSettingsInfo() settings.documents = documents settings.signers = signers ####Make a request to Signature Api for sign document #Sign document using current user id and sign settings response = signatureApi.SignDocument(clientId, body=settings) #If request was successful - set variables for template if response.status == 'Ok': time.sleep(5) #Get signature status getDocumentStatus = signatureApi.GetSignDocumentStatus(clientId, response.result.jobId) if getDocumentStatus.status == "Ok": #If document signed - get it's GUID guid = getDocumentStatus.result.documents[0].documentId else: error = response.error_message else: error = response.error_message #Create json string and return it to ajax request return_data = json.dumps({'responseCode': 200, 'guid': guid, 'clientId' : clientId, 'privateKey' : privateKey, 'error' : error}) return Response(body=return_data, content_type='application/json') # If email in post data - sign document with out widget elif request.POST.get('email'): #Get post data clientId = request.POST.get('clientId') privateKey = request.POST.get('privateKey') email = request.POST.get('email') name = request.POST.get('name') lastName = request.POST.get('lastName') inputFile = request.POST.get('file') callbackUrl = request.POST.get('callbackUrl') guid = None fileName = None iframe = None # Checking required parameters if not clientId or not privateKey or not email or not name or not lastName: return render_to_response('__main__:templates/sample39.pt', dict(error='You do not enter all parameters')) #Get current work directory currentDir = os.path.dirname(os.path.realpath(__file__)) #Create text file fp = open(currentDir + '/../user_info.txt', 'w') #Write user info to text file fp.write(clientId + "\r\n" + privateKey) fp.close() #Check is temporary file with callback info is exist if os.path.exists(currentDir + '/../callback_info.txt'): #If exist delete it os.remove(currentDir + '/../callback_info.txt') ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create StorageApi object storage = StorageApi(apiClient) # Create SignatureApi object signature = SignatureApi(apiClient) try: #A hack to get uploaded file size inputFile.file.seek(0, 2) fileSize = inputFile.file.tell() inputFile.file.seek(0) #Get file stream fs = FileStream.fromStream(inputFile.file, fileSize) ####Make a request to Storage API using clientId #Upload file to current user storage response = storage.Upload(clientId, inputFile.filename, fs, overrideMode=0) if response.status != "Ok": raise Exception(response.error_message) #Get uploaded file GUID guid = response.result.guid #Get uploaded file name fileName = inputFile.filename except Exception, e: return render_to_response('__main__:templates/sample39.pt', {'error': str(e)}) try: # Create envelope using user id and entered by user name envelop = signature.CreateSignatureEnvelope(clientId, name=fileName) if envelop.status != "Ok": raise Exception(envelop.error_message) # Add uploaded document to envelope addDocument = signature.AddSignatureEnvelopeDocument(clientId, envelop.result.envelope.id, guid) if addDocument.status != "Ok": raise Exception(envelop.error_message) # Get role list for current user recipient = signature.GetRolesList(clientId) if recipient.status != "Ok": raise Exception(envelop.error_message) # Get id of role which can sign roleId = None for item in recipient.result.roles: if item.name == "Signer": roleId = item.id # add recipient addRecipient = signature.AddSignatureEnvelopeRecipient(clientId, envelop.result.envelope.id, email, name, lastName, roleId) if addRecipient.status != "Ok": raise Exception(envelop.error_message) # Get recipient id getRecipient = signature.GetSignatureEnvelopeRecipients(clientId, envelop.result.envelope.id) if getRecipient.status != "Ok": raise Exception(envelop.error_message) recipientId = getRecipient.result.recipients[0].id #Create Web hook object (callback) webHook = WebhookInfo webHook.callbackUrl = callbackUrl or None #Get document from envelop getEnvelopDocument = signature.PublicGetEnvelopeDocuments(envelop.result.envelope.id, recipientId) if getEnvelopDocument.status != "Ok": raise Exception(envelop.error_message) rand = random.randint(0, 500) #Create signature field object (max value of locationX,Y can be 1.0) SignatureEnvelopeFieldSettings = SignatureEnvelopeFieldSettingsInfo SignatureEnvelopeFieldSettings.locationX = "0.15" SignatureEnvelopeFieldSettings.locationY = "0.73" SignatureEnvelopeFieldSettings.locationWidth = "150" SignatureEnvelopeFieldSettings.locationHeight = "50" SignatureEnvelopeFieldSettings.name = "test" + str(rand) SignatureEnvelopeFieldSettings.forceNewField = True SignatureEnvelopeFieldSettings.page = "1" #Add signature field to document addField = signature.AddSignatureEnvelopeField(clientId, envelop.result.envelope.id, getEnvelopDocument.result.documents[0].documentId, recipientId, "0545e589fb3e27c9bb7a1f59d0e3fcb9", body=SignatureEnvelopeFieldSettings) if addField.status != "Ok": raise Exception(envelop.error_message) #Send envelop to API send = signature.SignatureEnvelopeSend(clientId, envelop.result.envelope.id, body=webHook) if send.status != "Ok": raise Exception(envelop.error_message) # make result messages message = '<p>File was uploaded to GroupDocs. Here you can see your <strong>' + name +\ '</strong> file in the GroupDocs Embedded Viewer.</p>' # Generation of iframe URL using jobInfo.result.outputs[0].guid iframe = 'https://apps.groupdocs.com/signature2/signembed/' + envelop.result.envelope.id +\ '/' + recipientId #Sign iframe URL iframe = signer.signUrl(iframe) except Exception, e: return render_to_response('__main__:templates/sample39.pt', {'error': str(e)})
def sample06(request): if request.content_type != 'application/json': return render_to_response('__main__:templates/sample06.pt', {}) #Request to json jsonPostData = request.json_body # import pdb; pdb.set_trace() #Get parameters clientId = jsonPostData["userId"] privateKey = jsonPostData["privateKey"] documents = jsonPostData['documents'] signers = jsonPostData['signers'] #Checking parameters if IsNotNull(clientId) == False or IsNotNull( privateKey) == False or IsNotNull(documents) == False or IsNotNull( signers) == False: return render_to_response( '__main__:templates/sample06.pt', {'error': 'You do not enter you User id or Private key'}) #Determination of placeSignatureOn parameter for i, signer in enumerate(signers): signers[i]['placeSignatureOn'] = '' ####Create Signer, ApiClient and Storage Api objects #Create signer object signerReq = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signerReq) #Create Signsture API object signatureApi = SignatureApi(apiClient) #Create setting variable for signature SignDocument method settings = SignatureSignDocumentSettingsInfo() settings.documents = documents settings.signers = signers ####Make a request to Signature Api for sign document #Sign document using current user id and sign settings response = signatureApi.SignDocument(clientId, body=settings) #If request was successfull - set variables for template error = '' if response.status == 'Ok': time.sleep(5) getDocumentStatus = signatureApi.GetSignDocumentStatus( clientId, response.result.jobId) if getDocumentStatus.status == "Ok": guid = getDocumentStatus.result.documents[0].documentId iframe = 'https://apps.groupdocs.com/document-viewer/embed/' + guid iframe = signerReq.signUrl(iframe) return_data = json.dumps({'responseCode': 200, 'url': iframe}) return Response(body=return_data, content_type='application/json') else: error = getDocumentStatus.error_message return render_to_response('__main__:templates/sample06.pt', {'error': response.error_message}) else: error = response.error_message return render_to_response('__main__:templates/sample06.pt', {'error': response.error_message})