Exemple #1
0
    def create_app(self):
        """Create the app."""
        from flask_iiif import IIIF
        from flask_restful import Api
        from flask_iiif.cache.simple import ImageSimpleCache

        app = Flask(__name__)
        app.config["DEBUG"] = True
        app.config["TESTING"] = True
        app.config["SERVER_NAME"] = "shield.worker.node.1"
        app.config["SITE_URL"] = "http://shield.worker.node.1"
        app.config["IIIF_CACHE_HANDLER"] = ImageSimpleCache()
        app.logger.disabled = True

        api = Api(app=app)

        iiif = IIIF(app=app)

        iiif.uuid_to_image_opener_handler(self.create_image)

        def api_decorator_test(*args, **kwargs):
            if "decorator" in kwargs.get("uuid"):
                abort(403)

        iiif.api_decorator_handler(api_decorator_test)

        iiif.init_restful(api)
        return app
Exemple #2
0
 def init_app(self, app):
     """Flask application initialization."""
     super(InvenioIIIFAPI, self).init_app(app)
     ext = IIIF(app=app)
     api = Api(app=app)
     ext.init_restful(api, prefix=app.config['IIIF_API_PREFIX'])
     ext.uuid_to_image_opener_handler(image_opener)
     ext.api_decorator_handler(protect_api)
Exemple #3
0
from flask_sqlalchemy import SQLAlchemy
from redis import Redis
from sqlalchemy_utils.types.json import JSONType

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
    'SQLALCHEMY_DATABASE_URI', 'sqlite:////tmp/test.db'
)
db = SQLAlchemy(app)
redis = Redis(host=os.environ.get('REDIS_HOST', 'localhost'), port=6379)
celery = Celery('app', broker=os.environ.get(
    'CELERY_BROKER_URL', 'redis://localhost:6379'
))

# Init the iiif extension
iiif = IIIF(app=app)
# Init the restful api
api = Api(app=app)
# Init restful api to flask-iiif
iiif.init_restful(api)


# Where iiif will find the images in our case `./images`
def uuid_to_source(uuid):
    image_path = os.path.join('./', 'images')
    return os.path.join(image_path, uuid)

# Init the opener function
iiif.uuid_to_image_opener_handler(uuid_to_source)

# Initialize the cache
 def test_creation_init(self):
     """Test extension creation init."""
     assert 'iiif' not in self.app.extensions
     r = IIIF()
     r.init_app(app=self.app)
     assert isinstance(self.app.extensions['iiif'], IIIF)