diff --git a/app/__init__.py b/app/__init__.py index 983ad409..2fcdcc67 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -53,13 +53,15 @@ def create_app(config_name="dev"): compress.init_app(app) md = Markdown(app, safe_mode=True) babel.init_app(app, locale_selector=get_locale) - """if db.session.get_bind().dialect.name == "postgresql": - lc_messages_query = db.session.execute(text("SHOW lc_messages;")) - psql_locale = lc_messages_query.fetchone()[0] - if psql_locale != "en_US.UTF-8": - warnings.warn("Your postgresql instance language is not english. Switching to English.") - db.session.execute(text("SET lc_messages TO 'en_US.UTF-8';")) - db.session.commit()""" + with app.app_context(): + if db.session.get_bind().dialect.name == "postgresql": + lc_messages_query = db.session.execute(text("SHOW lc_messages;")) + psql_locale = lc_messages_query.fetchone()[0] + if psql_locale != "en_US.UTF-8": + # ToDo: add an option in config.py to check something such as app.config["FORCE_PSQL_EN_LOCALE"] (with default on True) + warnings.warn("Your postgresql instance language is not english. Switching to English.") + db.session.execute(text("SET lc_messages TO 'en_US.UTF-8';")) + db.session.commit() # Register Jinja template functions from .main import main as main_blueprint app.register_blueprint(main_blueprint)