Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
 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()
Exemple #6
0
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")
Exemple #7
0
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
Exemple #8
0
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)
Exemple #9
0
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
Exemple #10
0
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")
Exemple #11
0
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)