diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index 975659a4..bfcb90d3 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -242,13 +242,11 @@ def create_app(app_name=None): language = 'en' if config.SERVER_MODE is False: # Get the user language preference from the miscellaneous module - misc_preference = Preferences.module('miscellaneous', False) - if misc_preference: - user_languages = misc_preference.preference( - 'user_language' - ) - if user_languages: - language = user_languages.get() or language + user_language = Preferences.raw_value( + 'miscellaneous', 'user_language' + ) + if user_language is not None: + language = user_language else: # If language is available in get request then return the same # otherwise check the session or cookie diff --git a/web/pgadmin/utils/preferences.py b/web/pgadmin/utils/preferences.py index c7127c95..10723309 100644 --- a/web/pgadmin/utils/preferences.py +++ b/web/pgadmin/utils/preferences.py @@ -473,6 +473,39 @@ class Preferences(object): options, help_str, category_label ) + @staticmethod + def raw_value(_module, _preference, _category=None): + + # Find the entry for this module in the configuration database. + module = ModulePrefTable.query.filter_by(name=_module).first() + + # Can't find the reference for it in the configuration database, + # create on for it. + if module is None: + return None + + if _category is None: + _category = _module + + cat = PrefCategoryTbl.query.filter_by(mid=module.id).filter_by(name=_category).first() + + if cat is None: + return None + + pref = PrefTable.query.filter_by(name=_preference).filter_by(cid=cat.id).first() + + if pref is None: + return None + + user_pref = UserPrefTable.query.filter_by( + pid=pref.id + ).filter_by(uid=current_user.id).first() + + if user_pref is not None: + return user_pref.value + + return None + @classmethod def module(cls, name, create=True): """