2012-03-06 22:14:10 +01:00
|
|
|
from flask import Flask, g, request, session
|
|
|
|
from flaskext.babel import Babel
|
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
|
2011-09-09 21:21:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config.from_object("default_settings")
|
2011-10-13 21:27:56 +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
|
|
|
|
db.create_all()
|
|
|
|
|
|
|
|
# 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()
|