def upload_image_m(request): data = is_worker(request) if not data: json_response = json.dumps({"success": "false", "type": "notWorker"}) return HttpResponse(json_response, mimetype='application/json') try: case = Case.objects.filter(id=data['case_id'])[0] except KeyError: json_response = json.dumps({"success": "false", "type": "KeyError"}) return HttpResponse(json_response, mimetype='application/json') try: scan = Scan( patient=case.patient) scan.save() except IntegrityError: scan.delete() json_response = json.dumps({"success": "false", "type": "IntegrityError"}) return HttpResponse(json_response, mimetype='application/json') try: image_data = b64decode(data['image_string']) scan.file = ContentFile(image_data, "test.png") scan.save() #comment.scans.add(scan) case.scans.add(scan) #case.scan = scan #case.save() except IntegrityError: json_response = json.dumps({"success": "false", "type": "IntegrityError"}) return HttpResponse(json_response, mimetype='application/json') json_response = json.dumps({"success": "true", "type": "uploadSuccess"}) return HttpResponse(json_response, mimetype='application/json')
return HttpResponse(json_response, mimetype='application/json') try: case = Case.objects.filter(id=data['case_id'])[0] except KeyError: json_response = json.dumps({"success": "false", "type": "KeyError"}) return HttpResponse(json_response, mimetype='application/json') try: scan = Scan( patient=case.patient) scan.save() except IntegrityError: scan.delete() json_response = json.dumps({"success": "false", "type": "IntegrityError"}) return HttpResponse(json_response, mimetype='application/json') try: image_data = b64decode(data['image_string']) scan.file = ContentFile(image_data, "test.png") scan.save() #comment.scans.add(scan) case.scans.add(scan) #case.scan = scan #case.save() except IntegrityError: json_response = json.dumps({"success": "false", "type": "IntegrityError"})