Module: check_mk
Branch: master
Commit: d5c400d6914f47ae6f986ab7374b64b254648a53
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d5c400d6914f47…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 18 11:56:30 2012 +0100
Fixed problems when changing the language using the profile edit dialog
---
web/htdocs/index.py | 17 -----------------
web/htdocs/lib.py | 24 +++++++++++++++++++++++-
web/htdocs/wato.py | 22 ++++++++++++++++------
3 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index ab3c301..d6b0fd3 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -156,23 +156,6 @@ def connect_to_livestatus(html):
# Default auth domain is read. Please set to None to switch off authorization
html.live.set_auth_domain('read')
-def load_language(lang):
- # Make current language globally known to all of our modules
- __builtin__.current_language = lang
-
- if lang:
- locale_base = defaults.locale_dir
- po_path = '/%s/LC_MESSAGES/multisite.po' % lang
- # Use file in OMD local strucuture when existing
- if os.path.exists(local_locale_path + po_path):
- locale_base = local_locale_path
- try:
- i18n = gettext.translation('multisite', locale_base, languages = [
lang ], codeset = 'UTF-8')
- i18n.install(unicode = True)
- except IOError, e:
- # Fallback to hardcoded default if the given language does not exist
- __builtin__.current_language = config.default_language
-
# Main entry point for all HTTP-requests (called directly by mod_apache)
def handler(req, profiling = True):
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 5662752..cd5f0e9 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -24,7 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import grp, defaults, pprint, os, gettext
+import grp, defaults, pprint, os, gettext, __builtin__
nagios_state_names = { -1: "NODATA", 0: "OK", 1: "WARNING",
2: "CRITICAL", 3: "UNKNOWN", 4: "DEPENDENT" }
nagios_short_state_names = { -1: "PEND", 0: "OK", 1:
"WARN", 2: "CRIT", 3: "UNKN", 4: "DEP" }
@@ -147,6 +147,28 @@ def get_languages():
return languages
+def load_language(lang):
+ # Make current language globally known to all of our modules
+ __builtin__.current_language = lang
+
+ if lang:
+ locale_base = defaults.locale_dir
+ local_locale_path = defaults.omd_root + "/local/share/check_mk/locale"
+ po_path = '/%s/LC_MESSAGES/multisite.po' % lang
+ # Use file in OMD local strucuture when existing
+ if os.path.exists(local_locale_path + po_path):
+ locale_base = local_locale_path
+
+ try:
+ i18n = gettext.translation('multisite', locale_base, languages = [
lang ], codeset = 'UTF-8')
+ i18n.install(unicode = True)
+ except IOError, e:
+ # Fallback to hardcoded default if the given language does not exist
+ __builtin__.current_language = config.default_language
+ else:
+ # Replace the _() function to disable i18n again
+ __builtin__._ = lambda x: x
+
def pnp_cleanup(s):
return s \
.replace(' ', '_') \
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 27559f5..181857e 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -9007,14 +9007,13 @@ def register_rule(group, varname, valuespec = None, title = None,
#
def page_user_profile():
- html.header(_("Edit user profile"), javascripts = ['wato'],
stylesheets = ['check_mk', 'pages', 'wato', 'status'])
-
if not config.user_id:
raise MKUserError(None, _('Not logged in.'))
if not config.may('edit_profile') and not
config.may('change_password'):
raise MKAuthException(_("You are not allowed to edit your user
profile."))
+ success = None
if html.has_var('_save') and html.check_transaction():
try:
users = load_users()
@@ -9033,8 +9032,13 @@ def page_user_profile():
else:
# Remove the customized language
- del users[config.user_id]['language']
- del config.user['language']
+ if 'language' in users[config.user_id]:
+ del users[config.user_id]['language']
+ if 'language' in config.user:
+ del config.user['language']
+
+ # load the new language
+ load_language(config.get_language())
#
# Change the password if requested
@@ -9049,14 +9053,20 @@ def page_user_profile():
users[config.user_id]['password'] =
encrypt_password(password)
save_users(users)
-
- html.message(_("Successfully updated user profile."))
+ success = True
if password:
html.write("<script type='text/javascript'>if(top)
top.location.reload(); else document.location.reload();</script>")
+ else:
+ html.reload_sidebar()
except MKUserError, e:
html.add_user_error(e.varname, e.message)
+ html.header(_("Edit user profile"), javascripts = ['wato'],
stylesheets = ['check_mk', 'pages', 'wato', 'status'])
+
+ if success:
+ html.message(_("Successfully updated user profile."))
+
if html.has_user_errors():
html.show_user_errors()