Example #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
Example #2
0
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
app.config["IIIF_CACHE_HANDLER"] = redis


@celery.task()
def make_sip(recid, data):
    now = datetime.datetime.now().isoformat()
    with open("./{0}_{1}.zip".format(recid, now), "wb") as f:
        f.write(zlib.compress(json.dumps(data).encode("utf-8")))


class Record(db.Model):
    __tablename__ = "record"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    json = db.Column(JSONType)