Example #1
0
def create_app(config=None, app_name=None, blueprints=None):
    """Create a Flask app."""

    if app_name is None:
        app_name = DefaultConfig.PROJECT
    if blueprints is None:
        blueprints = DEFAULT_BLUEPRINTS

    app = Flask(
        app_name,
        instance_path=INSTANCE_FOLDER_PATH,
        instance_relative_config=True,
        static_url_path="/static",
        static_folder="static",
    )

    app.config["dbname"] = config.DB_NAME
    app.config["dbhost"] = config.DB_HOST
    app.config["dbport"] = config.DB_PORT

    configure_app(app, config)
    configure_bundles(app)
    configure_hook(app)
    configure_blueprints(app, blueprints)
    configure_extensions(app)
    configure_logging(app)
    configure_error_handlers(app)
    configure_database(app)
    configure_login_manager(app)

    app.secret_key = r"A88dj\?1f ~!@xjRIYA?,TR"

    @app.before_request
    def before_request():
        if request.path != "/" and request.path[0:8] != "/static/":
            db_conn = rethinkdb.connect(app.config["dbhost"], app.config["dbport"])
            g.uow = UoW(db_conn)

    return app
Example #2
0
def get(
    graph,
    types="auto",
    image_patterns=["\.[png|jpg|gif]$"],
    label_properties=LABEL_PROPERTIES,
    hierarchy_properties=[RDFS.subClassOf, RDFS.subPropertyOf],
    add_types_labels=True,
    dbname="RDFLib LOD App",
):

    """
    Get the LOD Flask App setup to serve the given graph
    """

    app = Flask(__name__)

    app.config["graph"] = graph
    app.config["dbname"] = dbname

    app.config["types"] = types

    app.config["js"] = {"endpoint": "static", "filename": "lod.js"}
    app.config["jssetup"] = "lodsetup()"

    app.config["label_properties"] = label_properties
    app.config["hierarchy_properties"] = hierarchy_properties
    app.config["add_types_labels"] = add_types_labels

    app.register_blueprint(endpoint)
    app.register_blueprint(lod)

    app.add_url_rule("/", "index", index)

    # make sure we get one session per app
    app.config["SESSION_COOKIE_NAME"] = "SESSION_" + re.sub("[^a-zA-Z0-9_]", "_", str(graph.identifier))
    app.secret_key = "veryverysecret" + str(graph.identifier)

    return app