Example #1
0
    def get(self, _id):
        image = ImageModel.find_by_id(_id)

        if not image:
            return {'message': 'Image not found.'}, 404

        return image.json()
Example #2
0
    def delete(self, _id):
        image = ImageModel.find_by_id(_id)

        status = 404
        message = 'Image not found'
        if image:
            image.delete()
            status = 200
            message = 'Image deleted'

        return {'message': message}, status
Example #3
0
 def put(cls, image_id: int):
     image = ImageModel.find_by_id(image_id)
     req = request.get_json()
     identity = get_jwt_identity()
     if identity != image.user_id:
         return {"message": "you are not allowed to do that"}, 401
     if "caption" not in req:
         return {"message": "caption not in json"}, 400
     if image:
         image.caption = req["caption"]
         image.save_to_db()
         return {"msg": "caption has changed"}, 201
     return {"message": "image-id dne"}
    def put(cls, label_id: str, image_id: str):

        image = ImageModel.find_by_id(image_id)

        print("image.name", image.name)

        meta_data = json.loads(image.meta_data)
        bounding_box = meta_data['bounding_box']
        print("top_left_y", bounding_box['top_left']['y'])
        print("top_left_y", round(bounding_box['top_left']['y']))
        print("top_left_y", int(round(bounding_box['top_left']['y'])))

        # image.save_to_db()

        return image.json(), 200
Example #5
0
    def put(self, _id):
        data = parser.parse_args()

        image = ImageModel.find_by_id(_id)

        status = 200
        if image:
            image.type = data['type']
            image.url = data['url']
        else:
            image = ImageModel(data['type'], data['url'], data['product_id'])
            status = 201

        image.save()

        return image.json(), status
 def get(self, label_id: str, image_id: str):
     """
     This endpoint returns the requested i   mage if exists. It will use
     JWT to retrieve user information and look for the image
     inside the label's folder.
     """
     image = ImageModel.find_by_id(image_id)
     filename = image.name
     # folder = label_name
     # check if filename is URL secure
     if not image_helper.is_filename_safe(filename):
         return {"message": IMAGE_ILLEGAL_FILENAME.format(filename)}, 400
     try:
         # try to send the requested file to the user with status code 200
         # abs_path = image_helper.get_path(filename, folder=folder)
         # abs_path_list = abs_path.split("\\")
         # abs_path_list.pop()
         # path = "\\".join(abs_path_list)
         path = "..\static\images"
         return send_from_directory(path, filename)
     except FileNotFoundError:
         return {"message": IMAGE_NOT_FOUND.format(filename)}, 404
    def delete(self, label_id: str, image_id: str):
        """
        This endpoint is used to delete the requested image under the user's
        folder. It uses the JWT to retrieve user information.
        """
        image = ImageModel.find_by_id(image_id)
        filename = image.name

        # check if filename is URL secure
        if not image_helper.is_filename_safe(filename):
            return {"message": IMAGE_ILLEGAL_FILENAME.format(filename)}, 400

        try:
            image_path = os.path.abspath(f'static/images/{filename}')
            image.delete_from_db()
            os.remove(image_path)
            return {"message": IMAGE_DELETED.format(filename)}, 200

        except FileNotFoundError:
            return {"message": IMAGE_NOT_FOUND.format(filename)}, 404
        except Exception:
            traceback.print_exc()
            return {"message": IMAGE_DELETE_FAILED}, 500
Example #8
0
 def delete(cls, _id: int):
     image = ImageModel.find_by_id(_id)
     if image:
         image.delete_from_db()
         return {"message": "image deleted"}, 200
     return {"message": "image not found"}, 404
Example #9
0
 def delete(self, _id):
     image = ImageModel.find_by_id(_id)
     if image:
         image.delete_from_db()
         return {'message': 'Image has been deleted.'}