def invoice_item_image(request, ack_id=None): if request.method.lower() == "post": try: credentials = request.user.aws_credentials key = credentials.access_key_id secret = credentials.secret_access_key except AttributeError as e: logger.error(e) key = '' secret = '' filename = save_upload(request) if ack_id: key = u"invoice/{0}/item/image/{1}".format(ack_id, filename.split('/')[-1]) else: key = u"invoice/item/image/{0}".format(filename.split('/')[-1]) obj = S3Object.create(filename, key, 'media.dellarobbiathailand.com', key, secret) serializer = S3ObjectSerializer(obj) response = HttpResponse(JSONRenderer().render(serializer.data), content_type="application/json") response.status_code = 201 return response # If any method other than POST else: response = HttpResponse('{"message": "Not Allowed"}', content_type='application/json; charset=utf-8') response.status_code = 405 return response
def product_image(request): if request.method == "POST": credentials = request.user.aws_credentials key = credentials.access_key_id secret = credentials.secret_access_key try: filename = request.FILES["file"].name except MultiValueDictKeyError: filename = request.FILES["image"].name filename = save_upload(request, filename=filename) logger.debug(filename) obj = S3Object.create( filename, "acknowledgement/item/image/{0}_{1}".format(time.time(), filename.split("/")[-1]), "media.dellarobbiathailand.com", key, secret, ) logger.debug(obj.__dict__) response = HttpResponse( json.dumps({"id": obj.id, "url": obj.generate_url(key, secret)}), content_type="application/json" ) response.status_code = 201 return response
def employee_image(request): if request.method == "POST": filename = save_upload(request) obj = S3Object.create(filename, "employee/image/{0}.jpg".format(datetime.now().microsecond), 'media.dellarobbiathailand.com') response = HttpResponse(json.dumps({'id': obj.id, 'url': obj.generate_url()}), content_type="application/json") response.status_code = 201 return response
def acknowledgement_item_image(request): if request.method == "POST": filename = save_upload(request) obj = S3Object.create(filename, "acknowledgement/item/image/{0}.jpg".format(time.time()), 'media.dellarobbiathailand.com') response = HttpResponse(json.dumps({'id': obj.id, 'url': obj.generate_url()}), content_type="application/json") response.status_code = 201 return response
def process_image(self, request, **kwargs): """ Receives an image and processes it """ filename = save_upload(request) image = S3Object.create(filename, "user/image/{0}.jpg".format(time.time()), "media.dellarobbiathailand.com") #set Url, key and bucket data = {'url': image.generate_url(), "id": image.id, 'key': image.key, 'bucket': image.bucket} return self.create_response(request, data)
def supply_image(request): if request.method == "POST": credentials = request.user.aws_credentials key = credentials.access_key_id secret = credentials.secret_access_key filename = save_upload(request) obj = S3Object.create(filename, "supply/image/{0}.jpg".format(time.time()), 'media.dellarobbiathailand.com', key, secret) response = HttpResponse(json.dumps({'id': obj.id, 'url': obj.generate_url(key, secret)}), content_type="application/json") response.status_code = 201 return response
def process_image(self, request, **kwargs): """ Receives an image and processes it """ filename = save_upload(request) image = S3Object.create(filename, "user/image/{0}.jpg".format(time.time()), "media.dellarobbiathailand.com") #set Url, key and bucket data = { 'url': image.generate_url(), "id": image.id, 'key': image.key, 'bucket': image.bucket } return self.create_response(request, data)
def room_image(request): """ Uploads the file in the request """ if request.method.lower() == 'post': credentials = request.user.aws_credentials key = credentials.access_key_id secret = credentials.secret_access_key filename = save_upload(request) obj = S3Object.create(filename, 'project/room/image/{0}.jpg'.format(time.time()), 'media.dellarobbiathailand.com') return HttpResponse(json.dumps({'id': obj.id, 'url': obj.generate_url(key, secret)}), mimetype='application/json', status=201) else: return HttpResponse(status=401, mimetype="plain/text")
def product_image(request): if request.method == "POST": try: filename = request.FILES['file'].name except MultiValueDictKeyError: filename = request.FILES['image'].name filename = save_upload(request, filename=filename) obj = S3Object.create(filename, "acknowledgement/item/image/{0}_{1}".format(time.time(), filename.split('/')[-1]), 'media.dellarobbiathailand.com') response = HttpResponse(json.dumps({'id': obj.id, 'url': obj.generate_url(), 'key': obj.key, 'bucket':obj.bucket}), content_type="application/json") response.status_code = 201 return response
def item_schematic(request, schematic_id=0): """ Handles uploading item_schematic """ filename = save_upload(request) try: schematic = S3Object.objects.get(pk=schematic_id) except S3Object.DoesNotExist: try: obj_id = request.POST.get('id') schematic = S3Object.objects.get(pk=obj_id) except: key = 'project/item/schematic/{0}.jpg'.format(time.time()) schematic = S3Object.create(filename, key, 'media.dellarobbiathailand.com', encrypt_key=True) return HttpResponse(json.dumps(schematic.dict()), mimetype='application/json', status=201)
def estimate_file(request, q_id=None): if request.method == "POST": try: credentials = request.user.aws_credentials key = credentials.access_key_id secret = credentials.secret_access_key except AttributeError as e: logger.error(e) key = '' secret = '' filename = save_upload(request) if q_id: key = u"estimate/{0}/files/{1}".format(q_id, filename.split('/')[-1]) else: key = u"estimate/files/{0}".format(filename.split('/')[-1]) obj = S3Object.create(filename, key, u"document.dellarobbiathailand.com", key, secret) serializer = S3ObjectSerializer(obj) response = HttpResponse(JSONRenderer().render(serializer.data), content_type="application/json") response.status_code = 201 return response # If any method other than POST else: response = HttpResponse('{"message": "Not Allowed"}', content_type='application/json; charset=utf-8') response.status_code = 405 return response
def po_file(request, po_id=None): if request.method == "POST": try: credentials = request.user.aws_credentials key = credentials.access_key_id secret = credentials.secret_access_key except AttributeError as e: logger.error(e) key = '' secret = '' filename = save_upload(request) if po_id: key = u"purchase_order/{0}/files/{1}".format( po_id, filename.split('/')[-1]) else: key = u"purchase_order/files/{0}".format(filename.split('/')[-1]) obj = S3Object.create(filename, key, u"document.dellarobbiathailand.com", key, secret) serializer = S3ObjectSerializer(obj) response = HttpResponse(JSONRenderer().render(serializer.data), content_type="application/json") response.status_code = 201 return response # If any method other than POST else: response = HttpResponse('{"message": "Not Allowed"}', content_type='application/json; charset=utf-8') response.status_code = 405 return response
def room_image(request): """ Uploads the file in the request """ if request.method.lower() == 'post': credentials = request.user.aws_credentials key = credentials.access_key_id secret = credentials.secret_access_key filename = save_upload(request) obj = S3Object.create(filename, 'project/room/image/{0}.jpg'.format(time.time()), 'media.dellarobbiathailand.com') return HttpResponse(json.dumps({ 'id': obj.id, 'url': obj.generate_url(key, secret) }), mimetype='application/json', status=201) else: return HttpResponse(status=401, mimetype="plain/text")