def handle(self, *args, **options): with open('photos.pkl') as file: self.data = pickle.load(file) for each in self.data: id = each.get('id') url = each.get('url') product = self._get_product(id) filename = self._get_filename(url) photo = Photo(product=product) if filename in os.listdir(PHOTO_DIR): photo_path = '/'.join(['photos', filename]) photo.file = photo_path else: file_content = self._download(url) photo.file.save(filename, file_content) photo.save()
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')
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')