Beispiel #1
0
def upload(request, *args, **kwargs):
    if request.method == 'POST':
        try:
            if request.FILES:
                im = Image.open(request.FILES['Filedata'])
                if 'interlace' in im.info and im.format == 'PNG' and im.info['interlace'] == 1:
                    return HttpResponse('False')
                product = Product.objects.get(id=request.POST['product_id'])
                photo = Photo(
                    original = request.FILES['Filedata'],
                    product = product
                )
                response = {}
                if photo.is_valid():
                    photo.save() #500 error after this point, something to do with the f*****g response.  fix it you f****t.
                    response['success'] = True
                    return HttpResponse(json.dumps(response), mimetype="application/json")
                else:
                    response['success'] = False
                    response['error'] = 'Minimum image size is 640x480'
                    return HttpResponse(json.dumps(response), mimetype="application/json")
        except:
            import sys
            print(sys.exc_info()[0])
    return HttpResponse('hi')
Beispiel #2
0
def upload(request, *args, **kwargs):
    if request.method == 'POST':
        try:
            if request.FILES:
                im = Image.open(request.FILES['Filedata'])
                if 'interlace' in im.info and im.format == 'PNG' and im.info[
                        'interlace'] == 1:
                    return HttpResponse('False')
                product = Product.objects.get(id=request.POST['product_id'])
                photo = Photo(original=request.FILES['Filedata'],
                              product=product)
                response = {}
                if photo.is_valid():
                    photo.save(
                    )  #500 error after this point, something to do with the f*****g response.  fix it you f****t.
                    response['success'] = True
                    return HttpResponse(json.dumps(response),
                                        mimetype="application/json")
                else:
                    response['success'] = False
                    response['error'] = 'Minimum image size is 640x480'
                    return HttpResponse(json.dumps(response),
                                        mimetype="application/json")
        except:
            import sys
            print(sys.exc_info()[0])
    return HttpResponse('hi')