Patch to set language in System Settings

This commit is contained in:
Anand Doshi 2014-05-14 13:32:24 +05:30
parent 7d6b89cdb3
commit dd93e2b354
2 changed files with 24 additions and 0 deletions

View file

@ -28,3 +28,4 @@ frappe.patches.v4_0.deprecate_control_panel
frappe.patches.v4_0.file_manager_hooks
execute:frappe.get_doc("User", "Guest").save()
frappe.patches.v4_0.deprecate_link_selects
frappe.patches.v4_0.set_language_in_system_settings

View file

@ -0,0 +1,23 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from collections import Counter
from frappe.core.doctype.user.user import STANDARD_USERS
def execute():
if frappe.db.get_value("System Settings", "System Settings", "language"):
return
# find most common language
lang = frappe.db.sql_list("""select language from `tabUser`
where ifnull(language, '')!='' and language not like "Loading%%" and name not in ({standard_users})""".format(
standard_users=", ".join(["%s"]*len(STANDARD_USERS))), tuple(STANDARD_USERS))
lang = Counter(lang).most_common(1)
lang = (len(lang) > 0) and lang[0][0] or "english"
# set language in System Settings
system_settings = frappe.get_doc("System Settings")
system_settings.language = lang
system_settings.save()