def sample28(request): clientId = request.POST.get('clientId') privateKey = request.POST.get('privateKey') fileGuId = request.POST.get('fileId') basePath = request.POST.get('basePath') #Check is base path entered if not basePath: #If base path empty set base path to the dev server basePath = 'https://api.groupdocs.com/v2.0' url = None message = None # Checking required parameters if not clientId or not privateKey or not fileGuId: return render_to_response('__main__:templates/sample28.pt', dict(error='You do not enter all parameters')) ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Annotation object ant = AntApi(apiClient) ant.basePath = basePath try: # Make a request to Annotation API using clientId and fileGuId response = ant.ListAnnotations(clientId, fileGuId) if response.status == "Ok": if response.result.annotations: for i in range(len(response.result.annotations)): try: #Delete annotation by it's guid deleteAnnotation = ant.DeleteAnnotation(clientId, response.result.annotations[i].guid) if deleteAnnotation.status == "Ok": message = '<span style="color: red">There are no annotations</span>' ### If request was successful #Generation of iframe URL using $pageImage->result->guid #iframe to production server if basePath == "https://api.groupdocs.com/v2.0": url = 'https://apps.groupdocs.com/document-viewer/embed/' + fileGuId #iframe to dev server elif basePath == "https://dev-api.groupdocs.com/v2.0": url = 'https://dev-apps.groupdocs.com/document-viewer/embed/' + fileGuId #iframe to test server elif basePath == "https://stage-api.groupdocs.com/v2.0": url = 'https://stage-apps.groupdocs.com/document-viewer/embed/' + fileGuId elif basePath == "http://realtime-api.groupdocs.com": url = 'http://realtime-apps.groupdocs.com/document-viewer/embed/' + fileGuId url = signer.signUrl(url) except Exception, e: return render_to_response('__main__:templates/sample28.pt', dict(error=str(e))) else: message = '<span style="color: red">There are no annotations in this document</span>' except Exception, e: return render_to_response('__main__:templates/sample28.pt', dict(error=str(e)))
def sample28(request): clientId = request.POST.get("client_id") privateKey = request.POST.get("private_key") fileGuId = request.POST.get("fileId") basePath = request.POST.get("server_type") # Check is base path entered if basePath == "": # If base path empty set base path to the dev server basePath = "https://api.groupdocs.com/v2.0" url = "" message = "" # Checking required parameters if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(fileGuId) == False: return render_to_response("__main__:templates/sample28.pt", {"error": "You do not enter all parameters"}) ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Annotation object ant = AntApi(apiClient) ant.basePath = basePath try: # Make a request to Annotation API using clientId and fileGuId response = ant.ListAnnotations(clientId, fileGuId) if response.status == "Ok": if response.result.annotations: i = 0 for annotation in response.result.annotations: try: # Delete annotation by it's guid deleteAnnot = ant.DeleteAnnotation(clientId, response.result.annotations[i].guid) if deleteAnnot.status == "Ok": message = '<span style="color: red">There are no annotations</span>' ### If request was successfull # Generation of iframe URL using $pageImage->result->guid # iframe to prodaction server if basePath == "https://api.groupdocs.com/v2.0": url = "https://apps.groupdocs.com/document-viewer/embed/" + fileGuId # iframe to dev server elif basePath == "https://dev-api.groupdocs.com/v2.0": url = "https://dev-apps.groupdocs.com/document-viewer/embed/" + fileGuId # iframe to test server elif basePath == "https://stage-api.groupdocs.com/v2.0": url = "https://stage-apps.groupdocs.com/document-viewer/embed/" + fileGuId elif basePath == "http://realtime-api.groupdocs.com": url = "http://realtime-apps.groupdocs.com/document-viewer/embed/" + fileGuId url = signer.signUrl(url) except Exception, e: return render_to_response("__main__:templates/sample28.pt", {"error": str(e)}) i = i + 1 else: message = '<span style="color: red">There are no annotations in this document</span>' except Exception, e: return render_to_response("__main__:templates/sample28.pt", {"error": str(e)})
def sample38(request): clientId = request.POST.get('clientId') privateKey = request.POST.get('privateKey') inputFile = request.POST.get('file') url = request.POST.get('url') basePath = request.POST.get('basePath') fileId = request.POST.get('fileId') guid = None email = request.POST.get('email') firstName = request.POST.get('firstName') lastName = request.POST.get('lastName') # Checking required parameters if not clientId or not privateKey or not email or not firstName or not lastName: return render_to_response('__main__:templates/sample38.pt', dict(error='You do not enter all parameters')) ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Annotation object ant = AntApi(apiClient) api = StorageApi(apiClient) mgmtApi = MgmtApi(apiClient) if not basePath: basePath = 'https://api.groupdocs.com/v2.0' #Set base path ant.basePath = basePath api.basePath = basePath mgmtApi.basePath = basePath if url: try: # Upload file to current user storage using entered URl to the file upload = api.UploadWeb(clientId, url) guid = upload.result.guid fileId = None except Exception, e: return render_to_response('__main__:templates/sample38.pt', dict(error=str(e)))
def sample11(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') inputFile = request.POST.get('file') url = request.POST.get('url') basePath = request.POST.get('server_type') fileId = request.POST.get('fileId') guid = "" iframe = "" annotationType = request.POST.get('annotation_type') # Checking required parameters if IsNotNull(clientId) == False or IsNotNull( privateKey) == False or IsNotNull(annotationType) == False: return render_to_response('__main__:templates/sample11.pt', {'error': 'You do not enter all parameters'}) ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Annotation object ant = AntApi(apiClient) api = StorageApi(apiClient) if basePath == "": basePath = 'https://api.groupdocs.com/v2.0' #Set base path ant.basePath = basePath api.basePath = basePath if url != "": try: # Upload file to current user storage using entere URl to the file upload = api.UploadWeb(clientId, url) guid = upload.result.guid fileId = "" except Exception, e: return render_to_response('__main__:templates/sample11.pt', {'error': str(e)})
def sample11(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') inputFile = request.POST.get('file') url = request.POST.get('url') basePath = request.POST.get('server_type') fileId = request.POST.get('fileId') guid = "" iframe = "" annotationType = request.POST.get('annotation_type') # Checking required parameters if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(annotationType) == False: return render_to_response('__main__:templates/sample11.pt', { 'error' : 'You do not enter all parameters' }) ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Annotation object ant = AntApi(apiClient) api = StorageApi(apiClient) if basePath == "": basePath = 'https://api.groupdocs.com/v2.0' #Set base path ant.basePath = basePath api.basePath = basePath if url != "": try: # Upload file to current user storage using entere URl to the file upload = api.UploadWeb(clientId, url) guid = upload.result.guid fileId = "" except Exception, e: return render_to_response('__main__:templates/sample11.pt', { 'error' : str(e) })
user.lastname = lastName # Set email as entered email user.primary_email = email # user.roles = roles iframe = '' # Creating of new user newUser = mgmt.UpdateAccountUser(clientId, email, user) # Check the result of the request if newUser.status == "Ok": # Create AntApi object ant = AntApi(apiClient) ant.basePath = basePath # Make request to Ant api for set new user as annotation collaborator addCollaborator = ant.SetAnnotationCollaborators(clientId, guid, "2.0", body=[email]) # Make request to Annotation api to receive all collaborators for entered file id getCollaborators = ant.GetAnnotationCollaborators(clientId, guid) #Set reviewers rights for new user setReviewer = ant.SetReviewerRights(clientId, guid, getCollaborators.result.collaborators) # Generating iframe for template if basePath == "https://api.groupdocs.com/v2.0": iframe = 'https://apps.groupdocs.com/document-annotation2/embed/' + guid + '?&uid=' + newUser.result.guid + '&download=true' elif basePath == "https://dev-api.groupdocs.com/v2.0": iframe = 'https://dev-apps.groupdocs.com/document-annotation2/embed/' + guid + '?&uid=' + newUser.result.guid + '&download=true' elif basePath == "https://stage-api.groupdocs.com/v2.0":
def sample28(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') fileGuId = request.POST.get('fileId') basePath = request.POST.get('server_type') #Check is base path entered if basePath == "": #If base path empty set base path to the dev server basePath = 'https://api.groupdocs.com/v2.0' url = "" message = "" # Checking required parameters if IsNotNull(clientId) == False or IsNotNull( privateKey) == False or IsNotNull(fileGuId) == False: return render_to_response('__main__:templates/sample28.pt', {'error': 'You do not enter all parameters'}) ### Create Signer, ApiClient and Annotation Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Annotation object ant = AntApi(apiClient) ant.basePath = basePath try: # Make a request to Annotation API using clientId and fileGuId response = ant.ListAnnotations(clientId, fileGuId) if response.status == "Ok": if response.result.annotations: i = 0 for annotation in response.result.annotations: try: #Delete annotation by it's guid deleteAnnot = ant.DeleteAnnotation( clientId, response.result.annotations[i].guid) if deleteAnnot.status == "Ok": message = '<span style="color: red">There are no annotations</span>' ### If request was successfull #Generation of iframe URL using $pageImage->result->guid #iframe to prodaction server if basePath == "https://api.groupdocs.com/v2.0": url = 'https://apps.groupdocs.com/document-viewer/embed/' + fileGuId #iframe to dev server elif basePath == "https://dev-api.groupdocs.com/v2.0": url = 'https://dev-apps.groupdocs.com/document-viewer/embed/' + fileGuId #iframe to test server elif basePath == "https://stage-api.groupdocs.com/v2.0": url = 'https://stage-apps.groupdocs.com/document-viewer/embed/' + fileGuId elif basePath == "http://realtime-api.groupdocs.com": url = 'http://realtime-apps.groupdocs.com/document-viewer/embed/' + fileGuId url = signer.signUrl(url) except Exception, e: return render_to_response( '__main__:templates/sample28.pt', {'error': str(e)}) i = i + 1 else: message = '<span style="color: red">There are no annotations in this document</span>' except Exception, e: return render_to_response('__main__:templates/sample28.pt', {'error': str(e)})
user.lastname = lastName # Set email as entered email user.primary_email = email # user.roles = roles iframe = '' # Creating of new user newUser = mgmt.UpdateAccountUser(clientId, email, user) # Check the result of the request if newUser.status == "Ok": # Create AntApi object ant = AntApi(apiClient) ant.basePath = basePath # Make request to Ant api for set new user as annotation collaborator addCollaborator = ant.SetAnnotationCollaborators(clientId, guid, "2.0", body=[email]) # Make request to Annotation api to receive all collaborators for entered file id getCollaborators = ant.GetAnnotationCollaborators(clientId, guid) #Set reviewers rights for new user setReviewer = ant.SetReviewerRights( clientId, guid, getCollaborators.result.collaborators) # Generating iframe for template if basePath == "https://api.groupdocs.com/v2.0":
def sample42(request): clientId = request.POST.get("clientId") privateKey = request.POST.get("privateKey") fileId = request.POST.get("fileId") basePath = request.POST.get("basePath") iframe = None # Checking clientId, privateKey and fileId if not clientId or not privateKey or not fileId: return render_to_response("__main__:templates/sample42.pt", dict(error="You do not enter all parameters")) ####Create Signer, ApiClient and Storage Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create Ant Api object antApi = AntApi(apiClient) # Create Storage Api object storageApi = StorageApi(apiClient) # Create Async api object asyncApi = AsyncApi(apiClient) # Set base Path if not basePath: basePath = "https://api.groupdocs.com/v2.0" antApi.basePath = basePath asyncApi.basePath = basePath storageApi.basePath = basePath try: # Get all annotations from document getAllAnnotations = antApi.ListAnnotations(clientId, fileId) if getAllAnnotations.status == "Ok": # Create list of result document type convertType = ["pdf"] # Create JobInfo object and set attributes jobInfo = JobInfo() jobInfo.actions = "ImportAnnotations" jobInfo.out_formats = convertType jobInfo.status = "-1" jobInfo.email_results = True rand = random.randint(0, 500) jobInfo.name = "test" + str(rand) # Create job createJob = asyncApi.CreateJob(clientId, jobInfo) if createJob.status != "Ok": raise Exception(createJob.error_message) else: # Add document to the job addJobDocument = asyncApi.AddJobDocument(clientId, createJob.result.job_id, fileId, False) if addJobDocument.status != "Ok": raise Exception(addJobDocument.error_message) else: # Change job status jobInfo.status = "0" # Update job with new status updateJob = asyncApi.UpdateJob(clientId, createJob.result.job_id, jobInfo) if updateJob.status != "Ok": raise Exception(updateJob.error_message) time.sleep(5) # Get result file from job by it's ID getJobDocument = asyncApi.GetJobDocuments(clientId, createJob.result.job_id) if getJobDocument.status != "Ok": raise Exception(getJobDocument.error_message) else: # Get document GUID and Name from job fileGuid = getJobDocument.result.inputs[0].outputs[0].guid fileName = getJobDocument.result.inputs[0].outputs[0].name # Obtaining file stream of downloading file and definition of folder where to download file # Clear downloads folder currentDir = os.path.dirname(os.path.realpath(__file__)) if os.path.isdir(currentDir + "/../downloads"): # Get list of files for the_file in os.listdir(currentDir + "/../downloads"): file_path = os.path.join(currentDir + "/../downloads", the_file) try: # Delete file from folder os.unlink(file_path) except Exception, e: print e # Set path to were file will be downloaded newPath = currentDir + "/../downloads/" if not os.path.exists(newPath): os.makedirs(newPath) # Downlaoding of file fs = storageApi.GetFile(clientId, fileGuid) if fs: # Write file from stream to the downloads folder filePath = newPath + fileName with open(filePath, "wb") as fp: shutil.copyfileobj(fs.inputStream, fp) # Generate template message with link by clicking on which user can download file to he's local machine message = ( '<p><span style="color:green">File with annotations was downloaded to server\'s local folder. You can download it from <a href="/download_file?FileName=' + fileName + '">here</a></span></p>' ) # Generation of iframe URL using $pageImage->result->guid # iframe to production server if basePath == "https://api.groupdocs.com/v2.0": iframe = "https://apps.groupdocs.com/document-viewer/embed/" + fileGuid # iframe to dev server elif basePath == "https://dev-api.groupdocs.com/v2.0": iframe = "https://dev-apps.groupdocs.com/document-viewer/embed/" + fileGuid # iframe to test server elif basePath == "https://stage-api.groupdocs.com/v2.0": iframe = "https://stage-apps.groupdocs.com/document-viewer/embed/" + fileGuid elif basePath == "http://realtime-api.groupdocs.com": iframe = "http://realtime-apps.groupdocs.com/document-viewer/embed/" + fileGuid iframe = signer.signUrl(iframe) else: raise Exception("Wrong file ID!") else:
def sample22(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') fileId = request.POST.get('fileId') email = request.POST.get('email') name = request.POST.get('first_name') lastName = request.POST.get('last_name') callbackUrl = request.POST.get('callbackUrl') basePath = request.POST.get('server_type') # Checking required parameters if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(fileId) == False or IsNotNull(email) == False or IsNotNull(name) == False or IsNotNull(lastName) == False: return render_to_response('__main__:templates/sample22.pt', { 'error' : 'You do not enter all parameters' }) ### Create Signer, ApiClient and Mgmt Api objects # Create signer object signer = GroupDocsRequestSigner(privateKey) # Create apiClient object apiClient = ApiClient(signer) # Create mgmtApi object mgmt = MgmtApi(apiClient) # Declare which server to use mgmt.basePath = basePath #Create Role info object role = RoleInfo #Set user role Id. Can be: 1 - SysAdmin, 2 - Admin, 3 - User, 4 - Guest role.id = "3" #Set user role name. Can be: SysAdmin, Admin, User, Guest role.name = "User" #Create dict of roles. roles = [role] # Create User info object user = UserInfo # Set nick name as entered first name user.nickname = name # Set first name as entered first name user.firstname = name # Set last name as entered last name user.lastname = lastName # Set email as entered email user.primary_email = email # user.roles = roles iframe = '' # Creating of new user newUser = mgmt.UpdateAccountUser(clientId, email, user) # Check the result of the request if newUser.status == "Ok": # Create AntApi object ant = AntApi(apiClient) ant.basePath = basePath # Make request to Ant api for set new user as annotation collaborator addCollaborator = ant.SetAnnotationCollaborators(clientId, fileId, "2.0", body=[email]) # Make request to Annotation api to receive all collaborators for entered file id getCollaborators = ant.GetAnnotationCollaborators(clientId, fileId) #Set reviewers rights for new user setReviewer = ant.SetReviewerRights(clientId, fileId, getCollaborators.result.collaborators) # Make request to Annotation api to set CallBack session setCallBack = ant.SetSessionCallbackUrl(newUser.result.guid, fileId, callbackUrl) # Generating iframe for template if basePath == "https://api.groupdocs.com/v2.0": iframe = '<iframe src="https://apps.groupdocs.com/document-annotation2/embed/' + fileId + '?&uid=' + newUser.result.guid + '&download=true frameborder="0" width="720" height="600"></iframe>' elif basePath == "https://dev-api.groupdocs.com/v2.0": iframe = '<iframe src="https://dev-apps.groupdocs.com/document-annotation2/embed/' + fileId + '?&uid=' + newUser.result.guid + '&download=true frameborder="0" width="720" height="600"></iframe>' elif basePath == "https://stage-api.groupdocs.com/v2.0": iframe = '<iframe src="https://stage-apps.groupdocs.com/document-annotation2/embed/' + fileId + '?&uid=' + newUser.result.guid + '&download=true frameborder="0" width="720" height="600"></iframe>' errorMessage = newUser.error_message # If request was successfull - set variables for template return render_to_response('__main__:templates/sample22.pt', { 'userId' : clientId, 'privateKey' : privateKey, 'fileId' : fileId, 'email':email, 'name':name, 'lastName': lastName, 'callbackUrl': callbackUrl, 'iframe': iframe, 'errorMessage': errorMessage }, request=request)