2016-06-25 12:57:47 +02:00
|
|
|
import flask
|
|
|
|
import flask_bootstrap
|
2016-02-20 14:57:26 +02:00
|
|
|
|
2018-11-08 22:29:30 +02:00
|
|
|
from mailu import utils, debug, models, manage, configuration
|
2018-10-18 15:57:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
def create_app_from_config(config):
|
|
|
|
""" Create a new application based on the given configuration
|
|
|
|
"""
|
|
|
|
app = flask.Flask(__name__)
|
2018-11-08 22:29:30 +02:00
|
|
|
app.cli.add_command(manage.mailu)
|
2018-10-18 15:57:43 +02:00
|
|
|
|
|
|
|
# Bootstrap is used for basic JS and CSS loading
|
|
|
|
# TODO: remove this and use statically generated assets instead
|
|
|
|
app.bootstrap = flask_bootstrap.Bootstrap(app)
|
|
|
|
|
|
|
|
# Initialize application extensions
|
2018-10-18 17:55:07 +02:00
|
|
|
config.init_app(app)
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.init_app(app)
|
|
|
|
utils.limiter.init_app(app)
|
|
|
|
utils.babel.init_app(app)
|
|
|
|
utils.login.init_app(app)
|
2018-11-08 21:29:52 +02:00
|
|
|
utils.login.user_loader(models.User.get)
|
2018-10-18 15:57:43 +02:00
|
|
|
utils.proxy.init_app(app)
|
2018-11-08 21:29:52 +02:00
|
|
|
utils.migrate.init_app(app, models.db)
|
2018-10-18 15:57:43 +02:00
|
|
|
|
|
|
|
# Initialize debugging tools
|
2018-10-18 17:55:07 +02:00
|
|
|
if app.config.get("DEBUG"):
|
2018-10-18 15:57:43 +02:00
|
|
|
debug.toolbar.init_app(app)
|
2018-10-18 17:55:07 +02:00
|
|
|
# TODO: add a specific configuration variable for profiling
|
|
|
|
# debug.profiler.init_app(app)
|
2018-10-18 15:57:43 +02:00
|
|
|
|
|
|
|
# Inject the default variables in the Jinja parser
|
2018-10-18 17:55:07 +02:00
|
|
|
# TODO: move this to blueprints when needed
|
2018-10-18 15:57:43 +02:00
|
|
|
@app.context_processor
|
|
|
|
def inject_defaults():
|
|
|
|
signup_domains = models.Domain.query.filter_by(signup_enabled=True).all()
|
|
|
|
return dict(
|
|
|
|
signup_domains=signup_domains,
|
|
|
|
config=app.config
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import views
|
2021-01-06 18:05:21 +02:00
|
|
|
from mailu import ui, internal, api
|
2018-10-18 15:57:43 +02:00
|
|
|
app.register_blueprint(ui.ui, url_prefix='/ui')
|
|
|
|
app.register_blueprint(internal.internal, url_prefix='/internal')
|
2021-01-06 18:05:21 +02:00
|
|
|
if app.config.get('API'):
|
|
|
|
api.register(app)
|
2018-10-18 15:57:43 +02:00
|
|
|
|
|
|
|
return app
|
|
|
|
|
|
|
|
|
|
|
|
def create_app():
|
2021-01-06 18:05:21 +02:00
|
|
|
""" Create a new application based on the config module
|
2018-10-18 15:57:43 +02:00
|
|
|
"""
|
|
|
|
config = configuration.ConfigManager()
|
|
|
|
return create_app_from_config(config)
|
2016-02-20 14:57:26 +02:00
|
|
|
|