def sample22(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 = "" email = request.POST.get('email') name = request.POST.get('first_name') lastName = request.POST.get('last_name') # Checking required parameters if IsNotNull(clientId) == False or IsNotNull( privateKey) == 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) # Create StorageApi object storage = StorageApi(apiClient) if basePath == "": basePath = 'https://api.groupdocs.com/v2.0' #Set base path storage.basePath = basePath # Declare which server to use mgmt.basePath = basePath if url != "": try: # Upload file to current user storage using entere URl to the file upload = storage.UploadWeb(clientId, url) guid = upload.result.guid fileId = "" except Exception, e: return render_to_response('__main__:templates/sample16.pt', {'error': str(e)})
def sample22(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 = "" email = request.POST.get('email') name = request.POST.get('first_name') lastName = request.POST.get('last_name') # Checking required parameters if IsNotNull(clientId) == False or IsNotNull(privateKey) == 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) # Create StorageApi object storage = StorageApi(apiClient) if basePath == "": basePath = 'https://api.groupdocs.com/v2.0' #Set base path storage.basePath = basePath # Declare which server to use mgmt.basePath = basePath if url != "": try: # Upload file to current user storage using entere URl to the file upload = storage.UploadWeb(clientId, url) guid = upload.result.guid fileId = "" except Exception, e: return render_to_response('__main__:templates/sample16.pt', { 'error' : str(e) })
def sample22(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/sample22.pt', dict(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) # Create StorageApi object storage = StorageApi(apiClient) if not basePath: basePath = 'https://api.groupdocs.com/v2.0' #Set base path storage.basePath = basePath # Declare which server to use mgmt.basePath = basePath if url: try: # Upload file to current user storage using entered URl to the file upload = storage.UploadWeb(clientId, url) guid = upload.result.guid fileId = None except Exception, e: return render_to_response('__main__:templates/sample16.pt', dict(error=str(e)))
def sample01(request): clientId = request.POST.get('client_id') privateKey = request.POST.get('private_key') if IsNotNull(clientId) == False or IsNotNull(privateKey) == False: return render_to_response( '__main__:templates/sample01.pt', {'error': 'You do not enter you User id or Private key'}) ####Create Signer, ApiClient and Management Api objects #Create signer object signer = GroupDocsRequestSigner(privateKey) #Create apiClient object apiClient = ApiClient(signer) #Create Management Api object api = MgmtApi(apiClient) try: ####Make a request to Management API using clientId userInfo = api.GetUserProfile(clientId) except Exception, e: return render_to_response('__main__:templates/sample01.pt', {'error': str(e)})
def sample41(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') callbackUrl = request.POST.get('callbackUrl') emailsArray = request.POST.getall('email[]') guid = None iframe = None # Checking required parameters if not clientId or not privateKey or not emailsArray: return render_to_response('__main__:templates/sample41.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 if last list element is empty string if emailsArray[1] == '': #Remove empty element from list del emailsArray[1] ### 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) mgmtApi = MgmtApi(apiClient) antApi = AntApi(apiClient) if not basePath: basePath = "https://api.groupdocs.com/v2.0" #Set base path storage.basePath = basePath mgmtApi.basePath = basePath if url: try: # Upload file to current user storage using entered URl to the file upload = storage.UploadWeb(clientId, url) guid = upload.result.guid try: ####Make a request to Storage API using clientId #Obtaining all Entities from current user files = storage.ListEntities(userId=clientId, path='My Web Documents', pageIndex=0) #Obtaining file name for item in files.result.files: #selecting file names if item.guid == guid: fileName = item.name except Exception, e: return render_to_response('__main__:templates/sample41.pt', {'error': str(e)}) fileId = None except Exception, e: return render_to_response('__main__:templates/sample41.pt', {'error': str(e)})
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)