Beispiel #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))
Beispiel #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))
Beispiel #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()