Ejemplo n.º 1
0
def sample33(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    firstUrl = request.POST.get('url1')
    secondUrl = request.POST.get('url2')
    thirdUrl = request.POST.get('url3')
    basePath = request.POST.get('server_type')
    message = ""
    iframe = ""
    # Checking clientId, privateKey and file_Id
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample33.pt',
                                  { '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 Storage Api object
    storageApi = StorageApi(apiClient)
    #Create Async api object
    asyncApi = AsyncApi(apiClient)
    #Set base Path
    if basePath == "":
        basePath = "https://api.groupdocs.com/v2.0"
    storageApi.basePath = basePath
    asyncApi.basePath = basePath
    #Create list of URL's
    urlList = [firstUrl, secondUrl, thirdUrl]
    #Create empty list for uploaded files GUID's
    guidList = []
    for url in urlList:
        try:
            #Upload file
            upload = storageApi.UploadWeb(clientId, url)
            if upload.status == "Ok":
                #Add GUID of uploaded file to list
                guidList.append(upload.result.guid)
            else:
                raise Exception(upload.error_message)
        except Exception, e:
            return render_to_response('__main__:templates/sample33.pt',
                { 'error' : str(e) })
Ejemplo n.º 2
0
def sample33(request):
    clientId = request.POST.get('client_id')
    privateKey = request.POST.get('private_key')
    firstUrl = request.POST.get('url1')
    secondUrl = request.POST.get('url2')
    thirdUrl = request.POST.get('url3')
    basePath = request.POST.get('server_type')
    message = ""
    iframe = ""
    # Checking clientId, privateKey and file_Id
    if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
        return render_to_response('__main__:templates/sample33.pt',
                                  {'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 Storage Api object
    storageApi = StorageApi(apiClient)
    #Create Async api object
    asyncApi = AsyncApi(apiClient)
    #Set base Path
    if basePath == "":
        basePath = "https://api.groupdocs.com/v2.0"
    storageApi.basePath = basePath
    asyncApi.basePath = basePath
    #Create list of URL's
    urlList = [firstUrl, secondUrl, thirdUrl]
    #Create empty list for uploaded files GUID's
    guidList = []
    for url in urlList:
        try:
            #Upload file
            upload = storageApi.UploadWeb(clientId, url)
            if upload.status == "Ok":
                #Add GUID of uploaded file to list
                guidList.append(upload.result.guid)
            else:
                raise Exception(upload.error_message)
        except Exception, e:
            return render_to_response('__main__:templates/sample33.pt',
                                      {'error': str(e)})
Ejemplo n.º 3
0
def sample43(request):
    clientId = request.POST.get('clientId')
    privateKey = request.POST.get('privateKey')
    fileId = request.POST.get('fileId')
    inputFile = request.POST.get('file')
    url = request.POST.get('url')
    basePath = request.POST.get('basePath')
    message = None
    iframe = None
    # Checking clientId and privateKey
    if not clientId or not privateKey:
        return render_to_response('__main__:templates/sample43.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 Doc Api object
    docApi = DocApi(apiClient)
    #Create Storage Api object
    storageApi = StorageApi(apiClient)
    #Create Async api object
    asyncApi = AsyncApi(apiClient)
    #Create Merge api object
    mergeApi = MergeApi(apiClient)
    #Set base Path
    if not basePath:
        basePath = "https://api.groupdocs.com/v2.0"
    docApi.basePath = basePath
    mergeApi.basePath = basePath
    asyncApi.basePath = basePath
    storageApi.basePath = basePath
    if url:
        try:
            # Upload file to current user storage using entered URl to the file
            upload = storageApi.UploadWeb(clientId, url)
            guid = upload.result.guid
            fileId = None
        except Exception, e:
            return render_to_response('__main__:templates/sample43.pt',
                dict(error=str(e)))
Ejemplo n.º 4
0
 apiClient = ApiClient(signer)
 # Create StorageApi object
 storage = StorageApi(apiClient)
 # Create SignatureApi object
 signature = SignatureApi(apiClient)
 docApi = DocApi(apiClient)
 mergeApi = MergeApi(apiClient)
 asyncApi = AsyncApi(apiClient)
 if basePath == "":
     basePath = 'https://api.groupdocs.com/v2.0'
 #Set base path
 storage.basePath = basePath
 signature.basePath = basePath
 docApi.basePath = basePath
 mergeApi.basePath = basePath
 asyncApi.basePath = basePath
 guid = fileId
 #Create list with entered data
 enteredData = {
     "email": email,
     "country": country,
     "name": name,
     "street": street,
     "city": city
 }
 #Create new Datasource object
 dataSource = Datasource
 array = []
 #Create DataSourceField object and filing it with entered data
 for key, data in enteredData.iteritems():
     value = [data]
Ejemplo n.º 5
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:
Ejemplo n.º 6
0
 apiClient = ApiClient(signer)
 # Create StorageApi object
 storage = StorageApi(apiClient)
 # Create SignatureApi object
 signature = SignatureApi(apiClient)
 docApi = DocApi(apiClient)
 mergeApi = MergeApi(apiClient)
 asyncApi = AsyncApi(apiClient)
 if not basePath:
     basePath = 'https://api.groupdocs.com/v2.0'
     #Set base path
 storage.basePath = basePath
 signature.basePath = basePath
 docApi.basePath = basePath
 mergeApi.basePath = basePath
 asyncApi.basePath = basePath
 guid = templateGuid
 #Create list with entered data
 enteredData = {"email": email, "country": country, "name": name, "street": street, "city": city}
 #Create new Datasource object
 dataSource = Datasource
 array = []
 #Create DataSourceField object and filing it with entered data
 for key, data in enteredData.iteritems():
     value = [data]
     field = DatasourceField()
     field.name = key
     field.type = "text"
     field.values = value
     array.append(field)
     #Set DataSourceField object to the fields parameter of the DataSource object