2015-08-18 19:06:24 +02:00
|
|
|
import os
|
2015-04-30 16:57:37 +02:00
|
|
|
import warnings
|
|
|
|
|
2012-03-06 22:14:10 +01:00
|
|
|
from flask import Flask, g, request, session
|
2013-02-18 19:18:49 +01:00
|
|
|
from flask.ext.babel import Babel
|
2016-05-21 23:47:12 +02:00
|
|
|
from flask.ext.migrate import Migrate, upgrade
|
2012-06-10 01:49:01 +02:00
|
|
|
from raven.contrib.flask import Sentry
|
2012-03-06 22:14:10 +01:00
|
|
|
|
2011-10-15 02:24:02 +02:00
|
|
|
from web import main, db, mail
|
2011-09-11 22:11:36 +02:00
|
|
|
from api import api
|
2015-08-19 22:47:52 +02:00
|
|
|
from utils import PrefixedWSGI
|
2011-09-09 21:21:37 +02:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2015-08-19 22:40:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
def configure():
|
|
|
|
""" A way to (re)configure the app, specially reset the settings
|
|
|
|
"""
|
2015-08-18 19:06:24 +02:00
|
|
|
config_obj = os.environ.get('FLASK_SETTINGS_MODULE', 'merged_settings')
|
|
|
|
app.config.from_object(config_obj)
|
2015-08-19 22:47:52 +02:00
|
|
|
app.wsgi_app = PrefixedWSGI(app)
|
2015-08-19 22:40:07 +02:00
|
|
|
|
|
|
|
# Deprecations
|
|
|
|
if 'DEFAULT_MAIL_SENDER' in app.config:
|
|
|
|
# Since flask-mail 0.8
|
|
|
|
warnings.warn(
|
|
|
|
"DEFAULT_MAIL_SENDER is deprecated in favor of MAIL_DEFAULT_SENDER"
|
|
|
|
+" and will be removed in further version",
|
|
|
|
UserWarning
|
|
|
|
)
|
|
|
|
if not 'MAIL_DEFAULT_SENDER' in app.config:
|
|
|
|
app.config['MAIL_DEFAULT_SENDER'] = DEFAULT_MAIL_SENDER
|
|
|
|
|
|
|
|
configure()
|
2015-04-30 16:57:37 +02:00
|
|
|
|
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
app.register_blueprint(main)
|
2011-09-11 22:11:36 +02:00
|
|
|
app.register_blueprint(api)
|
2011-09-09 21:21:37 +02:00
|
|
|
|
|
|
|
# db
|
|
|
|
db.init_app(app)
|
|
|
|
db.app = app
|
2016-05-21 23:47:12 +02:00
|
|
|
|
|
|
|
# db migrations
|
|
|
|
migrate = Migrate(app, db)
|
|
|
|
|
|
|
|
# auto-execute migrations on runtime
|
|
|
|
with app.app_context():
|
|
|
|
upgrade()
|
2011-09-09 21:21:37 +02:00
|
|
|
|
|
|
|
# mail
|
|
|
|
mail.init_app(app)
|
|
|
|
|
2011-10-15 01:19:19 +02:00
|
|
|
# translations
|
2011-10-15 02:24:02 +02:00
|
|
|
babel = Babel(app)
|
2011-10-15 01:19:19 +02:00
|
|
|
|
2012-06-10 01:49:01 +02:00
|
|
|
# sentry
|
|
|
|
sentry = Sentry(app)
|
|
|
|
|
2011-10-15 01:19:19 +02:00
|
|
|
@babel.localeselector
|
|
|
|
def get_locale():
|
2011-10-17 00:03:41 +02:00
|
|
|
# get the lang from the session if defined, fallback on the browser "accept
|
|
|
|
# languages" header.
|
|
|
|
lang = session.get('lang', request.accept_languages.best_match(['fr', 'en']))
|
2011-10-16 23:38:27 +02:00
|
|
|
setattr(g, 'lang', lang)
|
|
|
|
return lang
|
2011-10-15 01:19:19 +02:00
|
|
|
|
2011-09-09 21:21:37 +02:00
|
|
|
def main():
|
|
|
|
app.run(host="0.0.0.0", debug=True)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|