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 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 setUp(self): """ Set up the environment for the test cases """ super(UserResourceTest, self).setUp() self.username = '******' self.password = '******' self.user = User.objects.create_superuser('tester', '*****@*****.**', 'test') self.user.user_permissions.add( Permission.objects.get(codename="add_user")) self.client.login(username='******', password='******') profile = Employee() profile.user = self.user profile.save() self.img = S3Object() self.img.save()
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 project_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, "project/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 project_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, "project/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 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")