Example #1
0
def busitize(request):
    if 'url' not in request.GET:
        raise HttpResponseBadRequest

    url = request.GET['url']
    image, created = Image.objects.get_or_create(url=url)

    if created:
        status_code = 201
        busitize_task.delay(image.id)
        status_text = "Initiated"
    else:
        status_code = image.status
        status_text = image.get_status_display()

    response_data = {
        'status_code': status_code,
        'status_text': status_text,
        'url': url
    }
    if image.status == Image.COMPLETED:
        response_data['busitized'] = image.busitized.url

    logger.debug(request.META.get('HTTP_ACCEPT'))

    if "application/json" in request.META.get('HTTP_ACCEPT', ''):
        response = HttpResponse(json.dumps(response_data),
                                "application/json",
                                status=status_code)
        response['Access-Control-Allow-Origin'] = "*"
        return response

    return render(request, "busitize.html", response_data, status=status_code)
Example #2
0
def busitize(request):
    if 'url' not in request.GET:
        raise HttpResponseBadRequest

    url = request.GET['url']
    image, created = Image.objects.get_or_create(url=url)

    if created:
        status_code = 201
        busitize_task.delay(image.id)
        status_text = "Initiated"
    else:
        status_code = image.status
        status_text = image.get_status_display()

    response_data = {
        'status_code': status_code,
        'status_text': status_text,
        'url': url
    }
    if image.status == Image.COMPLETED:
        response_data['busitized'] = image.busitized.url

    logger.debug(request.META.get('HTTP_ACCEPT'))

    if "application/json" in request.META.get('HTTP_ACCEPT', ''):
        response = HttpResponse(json.dumps(response_data), "application/json", status=status_code)
        response['Access-Control-Allow-Origin'] = "*"
        return response

    return render(request, "busitize.html", response_data, status=status_code)
Example #3
0
 def test_basic(self):
     test_images = [
         os.path.join(settings.TEST_IMAGES, filename)
         for filename in os.listdir(settings.TEST_IMAGES)
     ]
     for image_path in test_images:
         response = busitize.delay(image_path)
Example #4
0
 def test_basic(self):
     test_images = [os.path.join(settings.TEST_IMAGES, filename) for filename in os.listdir(settings.TEST_IMAGES)]
     for image_path in test_images:
         response = busitize.delay(image_path)