Exemplo n.º 1
0
def addall(request):
    try:
        images= HomeImages.objects.filter(user=request.user,is_active = True)
    except:
        messages.error(request, "Error. Did not find the image object")
        return HttpResponseRedirect("/home/")
    client = Client(CAPTRICITY_API_TOKEN_SUBMIT)        
    BATCH_NAME = get_random_batch_name(STORED_BATCH_NAME)

    batch_id = create_or_get_batch(client,BATCH_NAME)        
    documents = client.read_documents()
    
    document_id = filter(lambda x: x['name'] == CAPTRICITY_TEMPLATE_NAME, documents).pop()['id']
    client.update_batch(batch_id, { 'documents': document_id, 'name': BATCH_NAME })
    batchObject = ApiBatch.objects.create(name=BATCH_NAME,user = request.user)
  
    batchObject.save()
    for image in images:
        f = open(image.image.url, 'rb')
        try:
            batch_file = client.create_batch_files(batch_id, {'uploaded_file': f})
            imageObject = ApiBatchImage.objects.create(batch = batchObject, image = image)
            imageObject.save()
        except:
            pass            
    try:
        batchObject.status = status(client,batch_id)
        batchObject.submit = submit(client,batch_id)
        batchObject.success = True
        messages.success(request, "All images were successfully added to batch "+batchObject.name+" total images "+str(images.count()))
    except Exception, e:
        batchObject.status = str(e)
        batchObject.submit = ""
        batchObject.success = False
        messages.success(request, "There was an Error in the batch "+batchObject.name+" "+str(e))
Exemplo n.º 2
0
def addall(request):
    try:
        images = HomeImages.objects.filter(user=request.user, is_active=True)
    except:
        messages.error(request, "Error. Did not find the image object")
        return HttpResponseRedirect("/home/")
    client = Client(CAPTRICITY_API_TOKEN_SUBMIT)
    BATCH_NAME = get_random_batch_name(STORED_BATCH_NAME)

    batch_id = create_or_get_batch(client, BATCH_NAME)
    documents = client.read_documents()

    document_id = filter(lambda x: x['name'] == CAPTRICITY_TEMPLATE_NAME,
                         documents).pop()['id']
    client.update_batch(batch_id, {
        'documents': document_id,
        'name': BATCH_NAME
    })
    batchObject = ApiBatch.objects.create(name=BATCH_NAME, user=request.user)

    batchObject.save()
    for image in images:
        f = open(image.image.url, 'rb')
        try:
            batch_file = client.create_batch_files(batch_id,
                                                   {'uploaded_file': f})
            imageObject = ApiBatchImage.objects.create(batch=batchObject,
                                                       image=image)
            imageObject.save()
        except:
            pass
    try:
        batchObject.status = status(client, batch_id)
        batchObject.submit = submit(client, batch_id)
        batchObject.success = True
        messages.success(
            request, "All images were successfully added to batch " +
            batchObject.name + " total images " + str(images.count()))
    except Exception, e:
        batchObject.status = str(e)
        batchObject.submit = ""
        batchObject.success = False
        messages.success(
            request, "There was an Error in the batch " + batchObject.name +
            " " + str(e))
Exemplo n.º 3
0
def uploadAllImages():
    from captools.api import Client    
    from home.models import HomeImages
    from django.contrib.auth.models import User
    from Captricity.settings import CAPTRICITY_API_TOKEN, BATCH_NAME as STORED_BATCH_NAME, CAPTRICITY_TEMPLATE_NAME
    from api.views import get_random_batch_name,create_or_get_batch, status, submit
    from api.models import ApiBatch, ApiBatchImage
    
    users = User.objects.all()
    for user in users:
        images= HomeImages.objects.filter(user=user,is_active = True)            
        client = Client(CAPTRICITY_API_TOKEN)        
        BATCH_NAME = get_random_batch_name(STORED_BATCH_NAME)
    
        batch_id = create_or_get_batch(client,BATCH_NAME)        
        documents = client.read_documents()        
        document_id = filter(lambda x: x['name'] == CAPTRICITY_TEMPLATE_NAME, documents).pop()['id']
        client.update_batch(batch_id, { 'documents': document_id, 'name': BATCH_NAME })
        batchObject = ApiBatch.objects.create(name=BATCH_NAME,user = user)      
        batchObject.save()
        for image in images:
            f = open(PROJECT_PATH+"/../"+image.image.url, 'rb')
            try:
                batch_file = client.create_batch_files(batch_id, {'uploaded_file': f})
                imageObject = ApiBatchImage.objects.create(batch = batchObject, image = image)
                imageObject.save()
            except:
                pass            
        try:
            batchObject.status = status(client,batch_id)
            batchObject.submit = submit(client,batch_id)
            batchObject.success = True   
            print "Image saved"           
        except Exception, e:
            batchObject.status = str(e)
            batchObject.submit = ""
            batchObject.success = False    
            print "Big werror"        
        batchObject.save()
Exemplo n.º 4
0
batches = client.read_batches()
batch_id = filter(lambda x: x['name'] == BATCH_NAME, batches).pop()['id']
print "Batch ID: ", batch_id
print

# batch = client.read_batch(batch_id)
# print 'Batch: ', batch['name'], '-', batch['id']
# print


# To digitize a batch, you need a Document to serve as the blank template form.
# Documents can only be defined via the Captricity Web UI. Once your Document is created, 
# you can use the Captricity API to get the id of your document:

documents = client.read_documents()


# Select the id of the template you would like to use. -- Form_012rev1 -- created on 10.17.14
document_id = filter(lambda x: x['name'] == TEMPLATE_NAME, documents).pop()['id']
print 'Template ID: ', document_id
print


# sys.exit() # get out now
# Once you have the id of the document, you can assign the document to the batch. 
# You can also do this step after you have uploaded your files.

# client.update_batch(batch_id, { 'documents': document_id, 'name': BATCH_NAME })

Exemplo n.º 5
0
from captools.api import Client

if __name__ == '__main__':
    from api_token import API_TOKEN
    client = Client(API_TOKEN)

    documents = client.read_documents()
    document_id = filter(
        lambda x: x['name'] == 'Example School Survey Template',
        documents).pop()['id']

    job = client.create_jobs({'document_id': document_id})
    print job