Skip to content
Snippets Groups Projects
app.py 1.67 KiB
from flask import Flask, send_from_directory

from database.db import db
from config.config import ENV, get_app_config, get_static_url

# Create and configure our Flask app
app = Flask(__name__, static_url_path=get_static_url())
app.url_map.strict_slashes = False
app.config.from_object(get_app_config())

# Setup authentication
import imperial_ldap
imperial_ldap.init_app(app)
imperial_ldap.set_auth_type(imperial_ldap.config.AuthType.SESSION, redirect_url='auth.login')

# Add integration to the Materials API
import imperial_doc_materials
imperial_doc_materials.init_app(app)
imperial_doc_materials.set_redirect_url('auth.login')

# Setup panopto api
import imperial_panopto
imperial_panopto.init_app(app)
imperial_panopto.set_client_id("<SET YOUR CLIENT ID HERE>")
imperial_panopto.set_client_secret("<SET YOUR CLIENT SECRET HERE>")
app.register_blueprint(imperial_panopto.panopto_api_blueprint)
imperial_panopto.set_panopto_is_dev(ENV != 'prod')

db.init_app(app)

# Import all your database models just like below:
with app.app_context():
    from models.entity import Entity
    if app.config["SQLALCHEMY_DATABASE_URI"]:
        db.create_all()


# Serve all static assets for the frontend
@app.route('/static/<path:path>')
def serve_static_files(path):
    return send_from_directory('static', path)


# Register all routes from the blueprints module
from blueprints.home import home_blueprint
from blueprints.auth import auth_blueprint
app.register_blueprint(home_blueprint)
app.register_blueprint(auth_blueprint)

# Hook any custom Jinja templating functions
from config import CUSTOM_TEMPLATE_FUNCTIONS
app.jinja_env.globals.update(CUSTOM_TEMPLATE_FUNCTIONS)

if __name__ == '__main__':
    app.run()